I have an ExpandableListView
and I need to set a certain group (groupPosition is known and always the same) to be non-expandable and just start a new Activity
when clicked. Is there a method to do that?
UPDATE
I also need only one group to be expanded at a time, and tried the following (but this is not working properly):
getExpandableListView().setOnGroupClickListener(
new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent,
View v, int groupPosition, long id) {
if (groupPosition == 1) {
Toast.makeText(getApplicationContext(), "TEST",
Toast.LENGTH_SHORT).show();
} else if (groupPosition != lastExpandedGroupPosition) {
getExpandableListView().collapseGroup(
lastExpandedGroupPosition);
} else
getExpandableListView().expandGroup(groupPosition);
lastExpandedGroupPosition = groupPosition;
return true;
}
});
This will do the trick - check in onGroupClick for the group you want to handle specially, return true for it, return false for any you want to be handled by the default action (expand/collapse.)
mExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
if(groupPosition == 2) {
Toast.makeText(mContext, "Group 2 clicked", Toast.LENGTH_LONG).show();
return true;
} else
return false;
}
});
You can use OnGroupClickListener for ExpandableListView to restrict group clicks.
Updated
private int previousGroupPosition = -1;
private boolean isDoubleTap = false;
expLv.setOnGroupClickListener(new OnGroupClickListener()
{
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id)
{
if(previousGroupPosition != -1)
expLvTodoCategories.collapseGroup(previousGroupPosition);
if(previousGroupPosition != groupPosition || isDoubleTap)
{
isDoubleTap = false;
previousGroupPosition = groupPosition;
if(groupPosition == 1)
{
//Start Activity
}
else
{
expLv.expandGroup(groupPosition);
}
}
else
isDoubleTap = true;
return true;
}
});
Try the above code, It can be useful..
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