i’ve seen many simillar questions and every answer is very specific to the problem and no straight forward answer, or i found tutorials that show how to create a checkbox that’s checked on selected items.
And i’m having trouble understanding how to do it from those codes.
I am following a tutorial found Here, and that’s preaty much how my code looks only different names.
I Want to have a multipile selection ListView, when an item selected the background color is changed to mark the items i’ve selected.
Maybe i can acomplish this using a custom selector?
I understood the common way is to save the positions of selected and do something in the getView function.
I saw people creating ViewHolder, but i didn’t really understand what it has to do with anything.
Can someone please help me?
Thank in advance,
Eric
Well i finally solved it, hope this helps someone :
What i did was created an
ArrayList<Integer>that stores all the position of selected items, and toggle the background colors on clicks.In my Adapter i define:
With the following method :
which addes\removes items from the ArrayList
In my getView method :
This checks if the position is storred in the ArrayList. if it does, paint it as selected. if not, the opposite.
all is left is the OnItemClick listener, i added :
When YourAdapter is the adapter of your ListView
Hope this helps anyone, as it’s a generic answer 🙂