项目有个购物车功能,是用ExpandableListView实现的,最近让添加一个子view的点击事件让跳转到详情页面。很好,有个setOnChildClickListener可以轻松实现,但是设置完成后居然发现点击没效果,这就尴尬了。网上查了一下主要是以下两方面引起的:
1.在BaseExpandableListAdapter中的isChildSelectable方法返回了false
2.子view中有其他控件抢先获取了焦点
解决方法:
1.让isChildSelectable方法返回true
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
2.在子view的布局的顶层加上android:descendantFocusability="blocksDescendants",意思是获取焦点