First, click on the event setOnItemClickListener
Activity interfaces need to achieve AdapterView.OnItemClickListener
And calls lv.setOnItemClickListener (this) in OnCreate method
//i代表position @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { Toast.makeText(this, "点击"+i, Toast.LENGTH_SHORT).show(); }
Second, long press event setOnItemLongClickListener
Activity interfaces need to achieve AdapterView.OnItemLongClickListener
And calls lv.setOnItemLongClickListener (this) in OnCreate method
// Why here we need to return value it? true representatives digest event, we will not continue to pass. // false off event on behalf of indigestion, will continue to pass. Long press to be triggered, after the click event triggers @Override public boolean onItemLongClick (AdapterView <?> AdapterView, View View, int i, Long L) { Toast.makeText ( the this , "long press" + i, Toast.LENGTH_SHORT) the .Show (); return to true ; }