如何处理Android SimpleExpandableListAdapter条目选择 [英] How to handle Android SimpleExpandableListAdapter entry selection
问题描述
我已经在我的Android应用程序中使用SimpleExpandableListAdapter类型创建了可扩展列表。
但是,当我选择/点击其中一个子条目时,我如何检测到事件,我完全失望。
I have created an expandable list in my Android application using the SimpleExpandableListAdapter type. 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等,但似乎找不到(通过实验,或半小时的谷歌搜索)正确的处理程序例程应该是什么。
I've tried all the usual OnClickListener/OnChildClickListener etc, but can't seem to find (by experimentation, or half an hour googling) what the correct handler routines should be.
推荐答案
应该是:
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 说,事实上是这样做的。
Though, it sounds like you tried this... ExpandableListView.OnChildClickListener says that it is, in fact, the way to do it.
另外,你是否定义了allItemsAreEnabled()和/或isEnabled()为您的ListAdapter?你不应该,但也许他们当前被定义并返回错误的值?
Also, have you defined the methods allItemsAreEnabled() and/or isEnabled() for your ListAdapter? You shouldn't have to, but maybe they are currently defined and returning the wrong values?
这篇关于如何处理Android SimpleExpandableListAdapter条目选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!