OnTouch is used to determine which item of listView is clicked, ontouchlistview
In fact, this mainly uses the ListView method. Through the coordinates, you can determine which listView is currently used. I will not talk about it more, just look at the code,
Lv_flide.setOnTouchListener (new OnTouchListener (){
Float oldX = 0;
Float oldY = 0;
Public boolean onTouch (View v, MotionEvent event ){
// TODO Auto-generated method stub
Switch (event. getAction ()){
Case MotionEvent. ACTION_DOWN:
// Save the X and Y coordinates of the press.
OldX = event. getX ();
OldY = event. getY ();
Break;
Case MotionEvent. ACTION_UP:
// Obtain the X and Y coordinates of the start time.
Float newX = event. getX ();
Float newY = event. getY ();
// Use the pointToPosition method in the ListView to obtain the position in the clicked ListView.
Final int oldPosition = (ListView) v). pointToPosition (int) oldX, (int) oldY );
Int newPosition = (ListView) v). pointToPosition (int) newX, (int) newY );
If (newX-oldX> 20 & oldPosition = newPosition ){
// Obtain the View that is clicked in the ListView.
View = (ListView) v). getChildAt (oldPosition );
For (int n = 0; n <data. size (); n ++)
{
If (n = oldPosition)
{
DataMap. put (n, true );
}
Else
{
DataMap. put (n, false );
}
}
Index = oldPosition;
Adapter. notifyDataSetChanged ();
/* Holder. delete. setVisibility (View. VISIBLE );
Holder. delete. setTextColor (Color. RED );
// Delete a specified ListView item
Holder. delete. setOnClickListener (new OnClickListener (){
@ Override
Public void onClick (View arg0 ){
RemoveItemView (view, oldPosition );
}
});*/
// RemoveItemView (view, oldPosition );
}
Break;
Default:
Break;
}
Return false;
}
});