Beena
Beena

Reputation: 2354

How to programatically perform ExpandableListView child item click

I have one ExpandableListView in my view. I have implemented its child click listener and it's working perfectly.

@Override
public boolean onChildClick(ExpandableListView parent, View view,
        int groupPosition, int childPosition, long id) {
}

Now, i also want programatically perform child click. Is it possible to call it programmatically?

I have tried by returning my convertView on getChild() method and performing on click on that by,

((View)updateListAdapter.getChild(0, 2)).performClick();

but with no luck. It's not calling onChildClick() method.

Upvotes: 0

Views: 2298

Answers (2)

Muhammad Farhan Habib
Muhammad Farhan Habib

Reputation: 1809

yes its possible, all you need to get ChildView from ExpandableListView then performClick(), like:

expandableList.getExpandableListAdapter().getChildView(1, 0, true, null, null).performClick();

It works well...

once ChildView is in your pocket then you can also access & play with its sub-views, like:

(expandableList.getExpandableListAdapter().getChildView(1, 0, true, null, null).findViewById(R.id.btn_continue)).performClick();

hope it will help you

Upvotes: 0

kris larson
kris larson

Reputation: 31015

ExpandableListView does have a method

public boolean performItemClick (View v, int position, long id)

but there is just one position argument; where's the group/child?

I looked at the code, and what it wants is a flat position. So something like this should work (sorry I haven't tried it):

long packedPosition = ExpandableListView.getPackedPositionForChild(group, child);
int flatPosition = expListView.getFlatListPosition(packedPosition);
expListView.performItemClick(view, flatPosition, childId);

Upvotes: 1

Related Questions