在列表视图Android 1.6中同时使用onClickListener和onLongClickListener [英] Use both onClickListener and onLongClickListener in listview Android 1.6

查看:64
本文介绍了在列表视图Android 1.6中同时使用onClickListener和onLongClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ListView 中为 TextView 使用onClickListeneronLongClickListener.我看到在Android 1.6中,长按侦听器与on click侦听器一起被触发,这意味着当我长按时都被触发.但这不是将来版本中的情况.有什么解决办法吗?

I am using both onClickListener and onLongClickListener for a TextView in a ListView. I see that in Android 1.6, the long click listener is fired along with the on click listener meaning both are fired when I long click. But this is not the case in the future versions. Is there any fix for this?

@Override
public View getView(int position, View convertView, ViewGroup parent) {

  if (convertView == null) {
    LayoutInflater inflater = getLayoutInflater();
    row = inflater.inflate(R.layout.row, parent, false);
  }

  TextView tv = (TextView) row.findViewById(R.id.tv);

  tv.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        showMessage();
      }
  });

  tv.setOnLongClickListener(new View.OnLongClickListener() {
      @Override
      public boolean onLongClick(View v) {
        showLongMessage();
      }
  });
}

推荐答案

您是否在true .OnLongClickListener.html"rel =" noreferrer> OnLongClickListener 表示您不想进一步处理?

Did you return boolean true at the end of OnLongClickListener to indicate you don't want further processing?

这篇关于在列表视图Android 1.6中同时使用onClickListener和onLongClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆