简体   繁体   中英

How can I make ExpandableListView not selectable?

I have a expandable list view with all the list already expanded. I don't want the user to be able to selected any parent items (group items). I have made it so that clicking it will not collapse the list, but cannot figure out how to make the item un-selectable.

if anyone was wondering, this is how I solved it:

I added these two lines into my ExpandableListView xml.

android:listSelector="@android:color/transparent" 
android:cacheColorHint="@android:color/transparent"

Use isChildSelectable method to make your required child item clickable. Maintain the isChildSelectable boolean state in your child model object.

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return yourmodel.isChildSelectable;
}

我不知道你已经尝试了什么,但禁用整个列表应该无法选择一些东西。

You can set the header as unclickable before returning the view in getGroupView() of the adapter: view.setClickable(true); or view.setFocusable(false); depending on what exactly you want.

Edit: changed setClickable(false) to setClickable(true). Making the view clickable means that you can't click what is behind, the list selector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM