我想将 .xml 布局应用于网格视图...
这是 gridlayout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
然后在主要活动中(我正在使用片段):
public class Grid extends Fragment {
private View vi;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle saved) {
View c = inflater.inflate(R.layout.choose, container, false);
vi = c;
GridView gridView = (GridView) vi.findViewById(R.id.gridView1);
String[] numbers = { "A", "B", "C", "D", "E", "F", "G",
"H", "I" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(),
R.layout.gridlayout,
numbers);
gridView.setAdapter(adapter);
return c;
}
但程序打印错误
AndroidRuntime(4302): java.lang.IllegalStateException: ArrayAdapter requires
the resource ID to be a TextView
我试过了
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), android.R.layout.simple_list_item_1,
numbers);
而且效果很好......
请帮忙指出我的错误!!谢谢!