内容具有id属性'android.R.id.list'的视图,该属性不是ListFragment中的ListView类

时间:2014-06-09 09:12:48

标签: android list android-listview staggered-gridview

我正在使用https://github.com/etsy/AndroidStaggeredGrid创建一个StaggeredGridView。但是当我尝试初始化StaggeredGridView时如下: -

 public class HomeFragment extends ListFragment 
{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View vi = inflater.inflate(R.layout.fragment_home, container, false);




        mGridView =(StaggeredGridView)vi.findViewById(R.id.grid_view); // Issue here


        return vi;
    }
}

这是我的Xml文件: -

<com.etsy.android.grid.StaggeredGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:item_margin="8dp"
app:column_count="3" />

我收到以下错误: -

06-09 09:07:16.568: E/AndroidRuntime(1836): Caused by: java.lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class

如果我将ListFragment更改为Fragment我尝试设置适配器时会出现NullPointerException 可能是什么原因?

0 个答案:

没有答案