Android compatibility between ExpandableListView and CheckTextView/Checkbox

*爱你&永不变心* 提交于 2019-12-11 23:42:25

问题


I've created an activity, which has an expandable list view of category, and some of them as subcategory. They all need to be checkable. I used for subcategory, a checkedTextView. For category, I used a textView and a checkbox, because when we click on the category name, we need to expand it (it is an expandable list view after all !). For the selection, the listview is on "Multiple Choice Mode". The adapter as the list of checked items, and in the getchild/getgroup view(), I set the checkbox (or the checkedtextview) to the state given by the sparsebooleanarray (of the listview). For each checkbox i do :

holder.checkbox.setOnCheckedChangeListener(new checkListener(groupPosition));

so when i check a checkbox, i know what position it is in the listview.

But I have a lot of problem with that implementations (the position given is not good, etc). I use the method of expandable list view for get the flatlistposition, but I suspect the expandable list view isn't really compatible with the choiceMode or selection...

Is this right ? Did somebody already had difficulty to get a similar project working ?


回答1:


I've found a post that say that the two way are incompatible, but I can't remember where.

I stick to the way I found, by associating a boolean array for groups, and a two dimensional boolean array for childs, and each click on a group or a child will change the boolean associate to the position.

It's a bit heavy but it works and we can do anything we want.



来源:https://stackoverflow.com/questions/5979947/android-compatibility-between-expandablelistview-and-checktextview-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!