我正在使用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
可能是什么原因?