当我们要使得一个listView可以同时处理长按事件和短按事件时,可以同时设置它的OnItemLongClickListener
和OnItemClickListener。值得注意的一点是,OnItemLongClickListener内部的onItemLongClick要返回true,
否知在长按事件激活的同时,短按事件也会激活。
示例如下:
listView.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id){ Toast.makeText(getApplicationContext(), "long click", Toast.LENGTH_LONG).show(); return true; } }); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "short click", Toast.LENGTH_LONG).show(); } });