How to obtain an item by pressing the listview Length

Source: Internet
Author: User

Encountered a problem during the preparation of notes

I added a long press event for each item in listview.

Java code
  1. Listview. setoncreatecontextmenulistener (New oncreatecontextmenulistener (){
  2. @ Override
  3. Public void oncreatecontextmenu (contextmenu menu, view V,
  4. Contextmenuinfo menuinfo ){
  5. Menu. setheadertitle ("operation ");
  6. Menu. Add (0, 0, 0, "delete ");
  7. }
  8. });

Then you need to process the actions when you click this long-pressed menu item.

Java code
  1. Public Boolean oncontextitemselected (menuitem item ){
  2. Return super. oncontextitemselected (item );
  3. }

I know this, but in this deletion process, I need to find the corresponding item in the listview to perform corresponding operations based on the item attribute, instead of the menu item I clicked, I found the answer on csdn

Java code
  1. Adapterview. adaptercontextmenuinfo menuinfo = (adapterview. adaptercontextmenuinfo) item. getmenuinfo ();

In this statement, menuinfo contains many attributes, where the ID is the ID of the listview, targetview, and items in the listview. Other method attributes can be used.

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.