Answer the question
In order to leave comments, you need to log in
Android ListView: how to use multiple and single groups at the same time?
Hello!
I am making my first application, I have never written any more questions, I found everything through the Internet, a lot has already been done, but I can’t cope with this problem. I've been sitting and suffering for a week without lying. I decided to ask for help anyway.
There is a ListView in which there are groups of elements: the heading of the group and the Checkable elements of the list itself. The whole difficulty is that the multipleChoice or singleChoice selection mode does not suit me, since I have groups of elements and such and such.
Imagine that this is the choice of pizza ingredients. The first group - the type of dough (thin / thick) - the only choice, the second group - additives (cheese, olives, sausage, etc.) - multiple choice.
At the moment, I did this: android:choiceMode="multipleChoice", I display the elements of the first group through the adapter with android:drawableLeft="?android:attr/listChoiceIndicatorSingle", the elements of the second group - with android:drawableLeft="?android:attr/ listChoiceIndicatorMultiple". But this, of course, is not enough, since single elements can still select several options. I got out like this: I check the ListView on the itemClick event - if the element is from a single group, then I remove the selection from other elements through setItemChecked. It works, the list looks like it should. But, a strange thing happens: setItemChecked for some reason gives a delay! And the choice of the list, as it were, slows down for half a second! That is, there was a Thin test type, we set Thick and the check transition moment slows down ... If setItemChecked is removed, there are no brakes. In the android:choiceMode="singleChoice" mode, there are no brakes when switching radio buttons either. And here manually if - is!
In general, this decision is probably a crutch and wrong. But I can't find another. It's like I'm the first person on the planet who needed single and multiple groups in one ListView! I do not believe it :)
Tell me, please, how to correctly implement what was planned? Thank you!
Answer the question
In order to leave comments, you need to log in
Throw out the leaves, use RecyclerView and use Adapter delegates. Make all checkboxes custom.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question