I’ve rearranged my code that dynamically creates widgets/views and, although the xml layout appears to be “well-formed” (it compiles), when I get to the corresponding “setContentView()” it crashes.
IOW:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ondemandandautomatic_dynamicauthorize); <-- crashes when I F6 (Eclipse) on this line
…So then I noticed in my xml layout file a warning icon: “This TableLayout is useless (no children, no background, no id)”
Well, I’m going to add the children at runtime; why does it need a background? And the big question: why does it say it has no id, when I’ve added one:
<TableLayout>
android:id="@id/tlDynamicRows" <-- IT'S RIGHT THERE!!!
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
There is another warning at the that says, “This TableRow or its TableRow parent is useless”
Here’s the entire xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tlDynamic"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow> <- This is where it says, "This TableRow or its TableRow parent is useless"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/demand"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/time"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/space"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/contact"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
<ScrollView
android:id="@+id/scrollViewHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<TableLayout> <- This is where it says, "says, "This TableRow or its TableRow parent is useless"
android:id="@id/tlDynamicRows"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
</ScrollView>
</LinearLayout>
What could be causing this revolting development?
Updated:
When looking over my post, I saw that the final “TableLayout” in the xml had a superfluous right angle bracket. So, I took the first one out, and now I get an err msg, namely, “No resource found that matches the given name (at ‘id’ with value ‘@id/tlDynamicRows’).”
That part of the xml is now:
<TableLayout
android:id="@id/tlDynamicRows"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
What gives?
Update:
Here’s the xml that finally works:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tlDynamic"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/demand"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/time"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/space"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:text="@string/contact"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
<ScrollView
android:id="@+id/scrollViewHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<TableLayout
android:id="@+id/tlDynamicRows"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
</ScrollView>
</LinearLayout>
I still had a warning message to change this line in the TableLayout inside the ScrollView:
android:layout_height="wrap_content"
to:
android:layout_height="wrap_content"
I did, and it seemed to make no difference – but it got rid of the Warning, so I’ll leave it.
There are several points to be noted in the XML you posted above:
1- When you are using the first Table Row
In this line you are not specifying the layout_height and layout_width attributes of the row, that is why you are getting “useless” in warning.
2- Another point is try giving id to Table Layout in Scroll view at the botton as:
instead of
hope these work for you.