Android - CheckBox blocks ExpandableListView.OnGroupClickListener

纵饮孤独 提交于 2019-12-21 04:52:18

问题


I'm trying to put a checkbox into ExpandableListView. How do I do that? I extend BaseExpandableListAdapter and put the following into getGroupView():

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
   ViewGroup parent) {
    View view = convertView == null ?
      context.getLayoutInflater().inflate(R.layout.onet_head, null) : convertView;
     ((TextView)view.findViewById(R.id.onetText)).setText(cats.get(groupPosition).value); 
    return view;
}

Notice that inflated layout? That's where I'm putting TextView and CheckBox. I noticed that placing a checkbox into my group row layout disables default group row functionality when clicking on the row makes a secondary (child) list appear. CheckBox is functioning as expected but when I click outside of the it the click is never detected by ether CheckBox or by OnGroupClickListener. I suspect that placing CheckBox into group row this way interferes with event detection/handling but thus far I'm not able to track it down

Can someone help me to resolve this? The CheckBox works fine though including detecting clicks when clicking directly on the box


回答1:


Anytime you place an item that is focusable in a list the list items no longer respond to clicks or anything like that. For every item you place in the list item that is focusable (buttons, checkboxes, etc), you need to set the android:focusable attribute to false.

I had a similar question and that was the answer for me. Android custom ListView unable to click on items



来源:https://stackoverflow.com/questions/1683514/android-checkbox-blocks-expandablelistview-ongroupclicklistener

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