【发布时间】:2015-06-11 14:01:59
【问题描述】:
我有一个标签页和片段。框架有一个“GridView”。我在片段父活动中使用 basedapter 内部类。
但是当我想将适配器设置为我的 gridview 时,我得到了 nullpointerexception。因为 GridView 变量总是为 null,请问如何解决这个问题?
Fragment 父 MainActivity OnCreate 方法;
GridView gv = (GridView)findViewById(R.id.gridview); // debugging and always null
gv.setAdapter(new AdapterB(this,WallPaperList));
片段 xml
<!-- TODO: Update blank fragment layout -->
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
MyGrid.xml(用于填充适配器)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imagepart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seç"
android:id="@+id/checkBox" />
</LinearLayout>
【问题讨论】:
标签: java android android-fragments gridview baseadapter