views:

84

answers:

2

Hello.

I am playing around with this example. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList2.html

I cannot figure out how to attach a listener to the children elements so that I can trigger some action when the user taps on the phone number.

Any code or links would be greatly appreciated.

A: 

You need to subscribe to setOnChildClickListener

getExpandableListView().setOnChildClickListener(this);

and implement OnChildClickListener

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
        int childPosition, long id) {
    // use groupPosition and childPosition to locate the current item in the adapter
    return true;
}
Pentium10
Does this apply to the example I linked to?It seems like that example does not implement ExpandableListView
Sure it does as it extends `ExpandableListActivity`
Pentium10
Thank you.Would you happen to know what's the proper way of getting the value or "label" of the clicked child?
You need to use the two int values to jump in the right position of the adapter(s) and get the value from it. Check the cursor you have methods to `moveToPosition(pos)`, then you simply get values from the cursor.
Pentium10
A: 

You should override onChildClick in your ExpandableListActivity extension.

Mayra