android - 将监听器添加到可扩展列表项中的子节点

标签 android android-listview

我使用了教程中给出的代码 http://mylifewithandroid.blogspot.com/2010/12/expandable-list-and-checkboxes.html 我附上了 ExpandableListView 的图片 enter image description here

SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
            this,
            createGroupList(),  
            R.layout.child_row, 
            new String[] { "CityName" },
            new int[] { R.id.childname },       
            createChildList(),  
            R.layout.child_row, 
            new String[] { "citydetails", "city" }, 
            new int[] { R.id.childname, R.id.city}  
        );

    setListAdapter( expListAdapter );

我需要一些关于如何将监听器添加到各个子节点的代码示例,例如单击地址应该将用户带到另一个 Activity 。 期待你的答复。 谢谢。

最佳答案

您还可以让您的 Activity 覆盖 onChildClick 方法:

@Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition, int childPosition, long id) {
    //implement logic to start the appropriate activity for this child.
}

来自 android 开发站点:onChildClick .

我还建议下载 API Demos .您可以了解有关设置的更多信息 here .

关于android - 将监听器添加到可扩展列表项中的子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8588701/

相关文章:

android - 配置 Qt Creator 以将 Clang 与 Qt for Android 结合使用

android - 如何根据 fragment 的类型设置 fragment 的操作栏和左抽屉属性

java - ReplaceAll() 未按预期工作并将辅助线程外部的值传递到主线程

java - ListView 显示两次所有行

android - 在 ListView 的列表项底部添加阴影

android - ListView 始终具有相同的 Intent

android - 任务 ':app:desugarDebugFileDependencies' 执行失败

android - 如何在ActionBar的navigation tabs中设置自定义View,并让tabs自适应高度?

java - ListView行上不同对象的不同点击事件

java - 从 ArrayList<HashMap<String, String>> 获取无效值