为root studio传递NULL会给我以下警告:

避免将NULL作为视图根传递(需要解析inflating 布局的根元素上的布局参数)

它在getGroupView中显示空值.请帮帮忙.

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                 HashMap<String, List<String>> listChildData) {
        super();
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);


        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}

推荐答案

而不是

convertView = infalInflater.inflate(R.layout.list_item, null);

convertView = infalInflater.inflate(R.layout.list_item, parent, false);

它将使用给定的父对象对其进行充气,但不会将其附加到父对象.

Android相关问答推荐

Android编写动画在发布版本中崩溃

推断的类型是片段,但应为上下文

Android 14上的慢速意图广播交付

如何在Jetpack Compose中更新异步回调的用户界面

在一列中垂直对齐两个框

在 Bash 脚本中使用 XMLLINT 解析 XML 单元测试文件,并将其放入数组中以表示成功和失败

如何在 compose android中将图像覆盖在另一个图像上

我需要在房间数据库中保留旧的自动迁移行吗?

Android Drawable文件夹中的图像显示模糊

通知使用默认语言,屏幕显示多种语言,同时通过 AppCompatDelegate 设置应用程序语言

在模块 jetified-kotlin-stdlib-1.8.10 中发现重复的类 kotlin.random.jdk8,带有启动基准

Electric Eel 后 Gradle 项目同步失败 | 2022.1.1更新

在 Jetpack Compose 中重用具有重复代码的列

组成不重叠的元素

使用 capacitor cordova 插件的 Android Studio 错误

如何将房间数据库导出到 .CSV

禁用通知权限后启动前台服务导致崩溃(Android 13)

Android Material Date Range Picker - 如何仅更改所选范围日期的文本 colored颜色 ?

MVVM - 这个逻辑的最佳层是什么?

Jetpack Compose Tapjacking:过滤对模糊 UI 的touch