How to disable extension for some elements in BaseExpandableListAdapter

I would like to disable extensibility for some of the items in the ExpandableListView .

So far I know this can be done by ExpandableListView , but I find it not good to control what to show / why / where NOT from the ListView - this task belongs to the adapter and there I want to disable extensibility.

So how do I do this from a class that extends BaseExpandableListAdapter ?

So far I've tried to set visibility convertView

to View.GONE

, but it doesn't work (i.e. it shows some kind of weird view, empty but not View.GONE

)

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    if (null == convertView) {
        convertView = inflater.inflate(R.layout.system_status_child, parent, false);
    }

    Item item = systemStatus.get(groupPosition);

    if(item.isStatusOk()){
        convertView.setVisibility(View.GONE);
    }
    else{
        convertView.setVisibility(View.VISIBLE);
        ((TextViewMuseo)convertView).setText(item.getChild_text());
    }

    return convertView;
}

      

system_status_child.xml

as follows:

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/system_status_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="some text" />

      

+3


source to share


1 answer


Just return 0 when children are counted for these groups:



@Override
public int getChildrenCount(int groupPosition) {
    if (groupPosition == 0 || groupPosition == 1) {
        return 0;
    } else {
        // return normal children count
    }
}

      

+5


source







All Articles