如何禁用 BaseExpandableListAdapter 中某些项目的扩展

How to disable expanding for some items in BaseExpandableListAdapter

我想禁用 ExpandableListView 中某些项目的可扩展性。

到目前为止,我知道它可以通过 ExpandableListView 完成,但我认为控制 show/why/where 不是来自 ListView 的内容是不好的 - 这个任务属于适配器,我想禁用可扩展性.

那么如何从扩展 BaseExpandableListAdapter 的 class 开始呢?

到目前为止,我已经尝试将 convertView 可见性设置为 View.GONE,但它不起作用(即它显示了一些奇怪的视图,空的但不是 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 看起来像这样:

<?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" />

只是 return 0 作为 children 这些组的计数:

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