The button control in the ListView gets the index of the item

Source: Internet
Author: User

The ListItem in the ListView sets the event response, and if there is a button control in ListItem, the Click event is not captured by ListItem, and the button in ListItem captures the click event. So what if you click on the button in ListItem to see which item the button is in, in other words, click the button in the ListItem to get the ListItem index? Given this index, the value inside the item is relatively easy.

The following methods can be implemented:

1. When the button is initialized in ListItem, add a SetPosition method to the button, pass in the index value at this time, and then call the view's GetPosition method in the button's onclick event. You can read the index of the ListItem in the following code:

Tagbutton.setpsition (position); The Tagbutton here is defined as the button,position is the position inside the view.

2. When the button is initialized, the index value of an item is passed through the SetPosition method

Private Onclicklistener Tagbuttononclick = new Onclicklistener () {

public void OnClick (View v) {

Final int index = (Integer) v.getposition ();

}}Index is the position in the item where the button is clicked, where you can get the value in the item.  

The button control in the ListView gets the index of the item

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.