When we want to enable a ListView to handle both long-press events and short-press events at the same time, you can set its Onitemlongclicklistener
and Onitemclicklistener. It is important to note that the Onitemlongclick inside the Onitemlongclicklistener to return True,
The short press event is also activated when a long press event is active.
Examples are as follows:
Listview.setonitemlongclicklistener (NewOnitemlongclicklistener () { Public BooleanOnitemlongclick (adapterview<?> Parent, view view,intPositionLongID) {Toast.maketext (Getapplicationcontext (),"Long Click", Toast.length_long). Show (); return true; } }); Listview.setonitemclicklistener (NewOnitemclicklistener () {@Override Public voidOnitemclick (adapterview<?> arg0, View arg1,intArg2,LongArg3) { //TODO auto-generated Method StubToast.maketext (Getapplicationcontext (), "Short Click", Toast.length_long). Show (); } });
Different reactions to the length and duration of Android