Android ExpandableListView OnChildClickListener无效

问题描述:

我有一个ExpandableListView,一切正常。我对每个孩子一个复选框行,我想切换当我点击如下子行:Android ExpandableListView OnChildClickListener无效

expandableListView.setOnChildClickListener(new OnChildClickListener() { 
    @Override 
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
     CheckBox checkBox = (CheckBox) v.findViewById(R.id.checkBox1); 
     checkBox.toggle(); 
     return true; 
    } 
}); 

的问题是,程序一直没有onChildClick()事件处理中进入。任何想法?

试试这个,

设置android:focusable=false复选框。如果它仍然不起作用,然后添加,

android:descendantFocussability=blocksDescendants到最上面的布局。

+0

仍然无法正常工作。 :/ – alicanbatur

+0

它解决了我的问题。谢谢。 – cameron

不要忘记启用

@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    // TODO Auto-generated method stub 
    return true; 
} 

如前所述here,你可能有以下行添加到您的复选框:

android:focusable="false" 
    android:clickable="false" 
    android:focusableInTouchMode="false" 

有了这个,我可以简单地使用的的OnChildClickListener ExpandableListView