How to handle Android SimpleExpandableListAdapter entry selection

前提是你 提交于 2019-12-11 16:35:16

问题


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.

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.

Any help greatfully appreciated.


回答1:


It 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
    }
}  

Though, it sounds like you tried this... ExpandableListView.OnChildClickListener says that it is, in fact, the way to do it.

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?




回答2:


Also...

If you happen to be using a class that extends BaseExpandableListAdapter then their is a default implemented method you'll have to set the return boolean for.

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

By default this method is returning false, swap to true(if this is the case) and your OnChildClickListener should start resolving correctly.



来源:https://stackoverflow.com/questions/2512436/how-to-handle-android-simpleexpandablelistadapter-entry-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!