首页 > 解决方案 > 不能与 ListFragment 中的自定义内容视图一起使用

问题描述

我需要使用方法

setEmptyText();

但是我使用屏幕片段,当我尝试运行我的应用程序时,错误:java.lang.IllegalStateException: Can't be used with a custom content view

退回给我,我读到这是因为我使用的是 Fragment 屏幕造成的。

public class ManejoFragment extends ListFragment ()

遵循返回此错误的方法示例:

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setListAdapter(null);
        View header = getActivity().getLayoutInflater().inflate(R.layout.device_list_header, null, false);
        getListView().addHeaderView(header, null, false);

        setEmptyText("Inicializando...");

        ((TextView) getListView().getEmptyView()).setTextSize(18);
        setListAdapter(listAdapter);
    } 

所有使用该方法的方法都setEmptyText()返回相同的错误。

标签: androidandroid-studiolayoutandroid-listview

解决方案


推荐阅读