Use both onClickListener and onLongClickListener in listview Android 1.6

dcanh121 picture dcanh121 · Jan 7, 2011 · Viewed 67.6k times · Source

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();
      }
  });
}

Answer

Tsan-Kuang Lee picture Tsan-Kuang Lee · Apr 10, 2011

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