My XML layout in res/layout/edit.xml:
<?xml version="1.0" encoding="utf-8"?>
<GridView
android:id="@+id/GridView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:numColumns="2">
<TextView
android:text="Person's Name"
android:id="@+id/PersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:text="Person's Points"
android:id="@+id/PersonPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</GridView>
When I try to switch from “edit.xml” to “Layout”, I see this error:
java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not
supported in AdapterView
I checked the documentation for AdapterView, and this is expected behavior. Why, then, does ADT expect it to work?
It’s because you’re trying to add two
TextViews to it in the xml. Don’t do that. The views for anyAdapterViewhave to come from the adapter.You’ll have to put your
TextViews in another Layout that contains yourGridViewas well. Layouts you can use are: FrameLayout, LinearLayout, RelativeLayout, TableLayout, or implement your own. I think what you are trying to do is have two buttons on top of aGridViewthat you will be providing an Adapter that will fill it.The two
TextViews will be the same size because of thelayout_weightattribute. The followingGridViewwill take up the rest of the space.If all you were trying to achieve was having the two
TextViews next to each other but being the same size then just use the secondLinearLayoutwith the horizontal orientation.