I have an ExpandableListView and I want to log the groupposition when clicking on a group. Unfortunately the code below returns always 0, as if I were clicking on the 0th group.
exList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
Log.i("group position", groupPosition + "");
return false;
}
});
I also have a longclicklistener on the groups and childs which works right:
exList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
groupPosition = ExpandableListView.getPackedPositionGroup(id);
...
}
Any ideas?
Make sure you have this for the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
You can't have a ExpandableListView into a ScrollView.
Use the listener OnGroupExpandListener, the param of the method onGroupExpand is the position of the group at the ExpandableListView.
Like that:
listView = (ExpandableListView) findViewById(R.id.expandableListView);
listView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Log.d(TAG, "pos " + groupPosition);
}
});
your expandable list view might be inside a scroll view. You can't have nested scroll.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With