OnTouch is used to determine which item of listView is clicked, ontouchlistview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.