Reputation: 327
I am using ExpandableListView
with "groups" and "childs" elements. Is it possible to disable expanding some of group elements ? Do I need to change some code in Adapter or should I override
onclick
method?
Upvotes: 2
Views: 961
Reputation: 460
Use setOnGroupClickListener
on your listview and return true
on the position you want to disable to be expended
this will disable the first element to be expended
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
if (i==0){
return true;
}
return false;
}
});
Upvotes: 1
Reputation: 3243
Call .setClickable(false) on those group headers that shall not trigger on click.
Your adapter gets a call to getGroupView
. This method returns the view that is displayed as the group header.
If you don't want this view clickable, call .setClickable(false)
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater li = LayoutInflater.from(activity);
convertView = li.inflate(<<your header item>>, null);
}
if (isLastGroup)
convertView.setClickable(false);
return convertView;
}
Upvotes: 1