【问题标题】:OnTouchListener being called too often in BaseAdapter in AndroidOnTouchListener 在 Android 的 BaseAdapter 中被频繁调用
【发布时间】:2016-01-28 05:18:09
【问题描述】:

我在CustomAdapter extends BaseAdapter 中的ImageView 上设置了OnTouchListener

方法如下:

 holder.projectImageImageView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Intent intent = new Intent(context1, test.class);
            intent.putExtra("projectInfo",projectItems);
            intent.putExtra("distributorInfo", distributorItems);
            intent.putExtra("contractorInfo",contractorItems);
            context1.startActivity(intent);
            return true;
        }
    });

所以,如果我的 ListView 中有 3 个项目并且我点击了一个项目 ImageView,为什么它会被称为我拥有的那么多项目?

【问题讨论】:

  • 在 MotionEvent 类中使用 UP_EVENT 来调用意图。

标签: android android-listview custom-adapter


【解决方案1】:

在我从 OnTouchListener 更改为 OnClickListener 之后,效果很好!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2012-02-17
    • 2019-02-17
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多