Encountered a problem during the preparation of notes
I added a long press event for each item in listview.
Java code
- Listview. setoncreatecontextmenulistener (New oncreatecontextmenulistener (){
- @ Override
- Public void oncreatecontextmenu (contextmenu menu, view V,
- Contextmenuinfo menuinfo ){
- Menu. setheadertitle ("operation ");
- Menu. Add (0, 0, 0, "delete ");
- }
- });
Then you need to process the actions when you click this long-pressed menu item.
Java code
- Public Boolean oncontextitemselected (menuitem item ){
- Return super. oncontextitemselected (item );
- }
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
- 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.