Listview in Android is bound to checkbox to realize the function of adding and deleting all (Demo)

The listview control is still very complex and should be commonly used in the project, so I wrote a small demo to talk about it, mainly about the usage of custom adapter, added a lot of judgment, etc Let's see the effect first!

OK, let's create a new project LvCheck@R_928_2419 @

Let's write these two layouts in advance. One is the main layout and the other is the item of listview XML, I believe there is no need to say more

activity_ main. xml

item. xml

item. XML has only two controls. It's easy to understand

Initialize control

We use the initview () method to initialize these controls

Then inherit the click event, button and listview

Custom adapter

The most difficult thing here is the adapter

1.Bean

For the convenience of data recording, we write an entity class in advance

listadapter

All here have written notes, which is also convenient for everyone to see

Of course, some methods are written later. We write them in advance, such as deleting and adding

Initialization data

We always need some data by default

Add data

Select all data

When we select all, the button should be unselected, so we have status here

Delete data

Deletion also needs to consider many factors

there

It is a calculation method. After we delete it, the array actually needs to be rearranged, and the button also needs to change back to the select all state

Listview Click

The above is the listview binding in Android introduced by Xiaobian Check@R_928_2419 @To realize the function of adding and deleting all (Demo), I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>