Baseexpandablelistadapter - Disable Onclick For Groupitems With No Childrens
I'm working on implementing an ExpandableListAdapter. Use case: I have group items I want to add to the Expandable list with no children. Problem is that every group item can be cl
Solution 1:
I have resorted to turning off the group indicators using (in an ExpandableListActivity
, do it manually on your list if you have a regular Activity):
getExpandableListView().setGroupIndicator(null);
Then in your getGroupView()
method that you are implementing check to see if the group you are about to make a view for has any children (I am using a List of Lists for mine so its rather straight forward) and style the group's view accordingly (make your own expander-button maybe). You might have to play around with the parent and convertView settings to see what works best for you.
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
convertView = inflater.inflate(
android.R.layout.simple_expandable_list_item_1, parent,
false);
if (groups.get(groupPosition).getMuscles().size() == 0) {
convertView.setEnabled(false); //Greys out group name
}
Solution 2:
There is other way to do this by setting onGroupClickListener
and returning true for the groups that dont have childs.
myExpandableList.setOnGroupClickListener(newOnGroupClickListener(){
publicbooleanonGroupClick(ExpandableListView parent, View v, int groupPosition, long id){
// TODO Auto-generated method stub.if(!myAdapter.containsChildren(groupPosition)){
returntrue;
}else{
returnfalse;
}
}});
Post a Comment for "Baseexpandablelistadapter - Disable Onclick For Groupitems With No Childrens"