我正在使用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
如果我在尝试设置适配器时将其更改为 NullPointerException 可能是什么原因ListFragment
?Fragment