How to create a click event for children in an extensible list

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

I cannot figure out how to connect the listener to the children elements so that I can trigger some actions when the user dials a phone number.

Any code or links are welcome.

+6
android events listener
source share
3 answers

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; } 
+20
source share

You must specify the location of the elements in an expandable list, for example

 listView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int group_position, int child_position, long id) { if(group_position==0 && child_position==0){ TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment); secondFragment.getView().setVisibility(View.VISIBLE); } else if(group_position==2 && child_position==2){ TryFragment secondFragment = (TryFragment) SampleActivity.this.getFragmentManager().findFragmentById(R.id.tryFragment); secondFragment.getView().setVisibility(View.VISIBLE); } return false; } }); 
+2
source share

You must override onChildClick in the ExpandableListActivity extension.

+1
source share

All Articles