0

我使用 SimpleExpandableListAdapter 类型在我的 Android 应用程序中创建了一个可扩展列表。But I'm at a complete loss as to how I detect events when one of the child entries has been selected/clicked.

我已经尝试了所有常用的 OnClickListener/OnChildClickListener 等,但似乎无法找到(通过实验或半小时谷歌搜索)正确的处理程序例程应该是什么。

非常感谢任何帮助。

4

2 回答 2

2

它应该是:

list.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    public void onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        Object o = (Object)adapter.getChild(groupPosition, childPosition);
        // perform work on child object here
    }
}  

虽然,听起来你尝试过这个...... ExpandableListView.OnChildClickListener说它实际上是这样做的方式。

另外,您是否为您的 ListAdapter 定义了 allItemsAreEnabled() 和/或 isEnabled() 方法?您不应该这样做,但也许它们当前已定义并返回错误的值?

于 2010-03-25T01:29:18.693 回答
1

还...

如果您碰巧使用扩展 BaseExpandableListAdapter 的类,那么它们是默认实现的方法,您必须为其设置返回布尔值。

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

默认情况下,此方法返回 false,交换为 true(如果是这种情况),您的 OnChildClickListener 应该开始正确解析。

于 2010-06-08T20:24:30.000 回答