Implementation code of listview multi selection deletion operation for Android
Recently, I tried to make a multi-choice demo of listview. It's not very difficult to see other people's examples online. I did it myself. Various details are not so simple. Now that you've done it, simply write down a note. Practice demo, naming notes are messy, don't mind.
Main interface layout activity_ main.xml
Layout of list items
The layout of the item is detailed once, and a button is added to the item, check@R_ 806_ 2419 @, imagebutton, etc., will only respond to the events of these controls, and the overall event of item will not respond. At the beginning, the attribute was not added and checked check@R_ 806_ 2419 @ after deletion, there is no response. It's also a little difficult to find this problem. I've seen the great gods recommend the layout analysis tool hierarchyviewer. This tool is similar to F12 in front-end development. It's very convenient to see each layout. Also curious, click to see the layout of the entire item, from the parent layout to the child layout, as long as check@R_ 806_ 2419 @ click is acceptable. All the others are false. That's the problem. Later, baidu came to the conclusion as above.
The solution is to add Android: descendantfocusability = "blocksdecedents" to the item layout of the list. After adding it, it is found that check@R_ 806_ 2419 @ can still be clicked alone without responding to the click and select event of the list. It's strange that there is no such phenomenon in other people's examples. Finally, you can only set check@R_ 806_ 2419 @ can't be clicked. The Android: clickable = "false" layout problem has been solved. The following is the source code of the Java class: first, the bean class, itembean.java
Custom adapter, mylistadapter.java
Finally, mainactivity. Java
Finally, there is the layout of the small menu. Let's put it on
All the codes have been placed. If you don't want to copy and paste, GitHub address: https://github.com/2767321434/ListChecked
The above is the whole content of this article. I hope it will help you learn Android Software Programming.