我想创建一个可扩展的listview
,当用户点击listview
(onChildClickListener?)的其中一个项目/子项时,它应该响应.任何人都可以帮助代码吗?我已经做了一个可扩展listview
的,我已经制作了自己的适配器和dataprovider类,但我不知道如何编写该onItemClick
部件.
您需要为子项和组项设置单独的单击侦听器,如下所示
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long l) { Item item = (Item) topicListAdapter.getChild(groupPosition,childPosition); handleClick(item); return false; } }); expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long l) { Item item = (item) topicListAdapter.getGroup(groupPosition); handleClick(item); return false; } });