【问题标题】:How to disable expanding for some items in BaseExpandableListAdapter如何禁用 BaseExpandableListAdapter 中某些项目的扩展
【发布时间】:2015-09-08 04:35:34
【问题描述】:

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

到目前为止,我知道它可以通过 ExpandableListView 完成,但我认为控制显示的内容/为什么/在哪里不是来自 ListView 并不好 - 这个任务属于适配器,我想在那里禁用可扩展性。

那么如何从扩展 BaseExpandableListAdapter 的类中做到这一点?

到目前为止,我已尝试将 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" />

【问题讨论】:

  • 你能不能一开始就返回一个不同的空白视图?

标签: android android-listview expandablelistview expandablelistadapter


【解决方案1】:

只返回 0 作为这些组的孩子数:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 2013-04-04
    • 2010-11-09
    相关资源
    最近更新 更多