I want to apply a .xml layout to a grid view...
This is the 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>
and then in main activity (i'm using fragments):
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;
}
but the programs prints error
AndroidRuntime(4302): java.lang.IllegalStateException: ArrayAdapter requires
the resource ID to be a TextView
I have tried
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity()
.getApplicationContext(), android.R.layout.simple_list_item_1,
numbers);
And it worked fine....
Please help and point out my mistakes!! thanks!