In my expandableListView I've made a custom button to expand/collapse the group and for expanding it works, but when collapsing no.
with this code
listView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Log.d("group click");
return true;
}
});
listView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Log.d("group collapse");
}
});
listView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Log.d("group expand");
}
});
With this code: when group is collapsed:
setOnGroupClickListener
when group is expanded:
setOnGroupClickListener
Why setOnGroupClickListener
is not loaded when I click on an expanded group ?
How to solve that ?
I've faced a somewhat similar problem. I needed all groups to always be expanded and clickable. To make it work, I wrote this monkey-code in my ExpandableListActivity
:
public void onCreate(Bundle savedInstanceState) {
...
// Expanding all.
for(int i = 0; i < adapter.getGroupCount(); i++)
getExpandableListView().expandGroup(i);
...
}
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
overrideStupidListBehaviour(groupPosition);
return false;
}
@Override
public void onGroupCollapse(int groupPosition) {
// Forbidding it to collapse.
getExpandableListView().expandGroup(groupPosition);
overrideStupidListBehaviour(groupPosition);
}
private void overrideStupidListBehaviour(int groupPosition) {
// Code to do when onGroupClick is called
}
I'm really interested, if there is a normal way to do that.
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}});
its very simple using this way
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(isExpanded){
//do something when expanded
}else{
//do something when collapsed or not expanded
}
...........
}
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