可扩展的列表视图; onitemClick

时间:2017-01-13 18:33:53

标签: android expandablelistview onitemclicklistener onitemclick

我想创建一个可扩展的listview,当用户点击listview(onChildClickListener?)的其中一个项目/子项时,它应该响应。任何人都可以帮助代码吗?我已经创建了一个可扩展的listview,我在其中创建了自己的适配器和dataprovider类,但我不知道如何编写onItemClick部分的代码。

1 个答案:

答案 0 :(得分:5)

您需要为子项和组项设置单独的单击侦听器,如下所示

    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;
        }
    });