BaseExpandableListAdapter - disable onclick for groupitems without children

I am working on implementing ExpandableListAdapter.

Use case:

I have group items that I want to add to an Expandable list without children. The problem is that every element in a group can be clicked even if they don't contain children.

Is there a way to disable / deselect an extension button to indicate to the user that it has no children?

At the moment I have implemented:

public void onGroupExpanded(int groupPosition) {
    if (!containsChildren(groupPosition)) {
        Toast.makeText(context, context.getString(R.string.err_no_children), Toast.LENGTH_LONG).show();
    }
}

      

I would prefer to have the visual information as mentioned above (disable / greyed out from the extension button) and show this toast if he clicks on it. Since the moment you can click on the groupItem it is trying to just expand the null items, which looks silly? Or is this the default good MMI behavior [1]?

[1] http://en.wikipedia.org/wiki/Man-machine_interface

+2


source to share


2 answers


I have resorted to disabling group indicators using (in ExpandableListActivity

, do it manually in your list if you have a normal activity):

getExpandableListView().setGroupIndicator(null);

      



Then in your method getGroupView()

that you implement to check if the group you are going to create the view has children (I'm using a list of lists for mine, so this is pretty straight forward) and (maybe make your own extension button). You may have to play around with parent and convertView settings to see which 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
        } 

      

0


source


There is another way to do this by setting onGroupClickListener

and returning true for groups that have no children.



myExpandableList.setOnGroupClickListener(new OnGroupClickListener(){

            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id){
                // TODO Auto-generated method stub.
                if(!myAdapter.containsChildren(groupPosition)){
                    return true;
                }else{
                    return false;                   
                }
            }});

      

0


source







All Articles