私はウィジェット/ビューを動的に作成するコードを再配置しました。xmlレイアウトは "整形式"(コンパイル)のように見えますが、対応する "setContentView()"に到達するとクラッシュします。コンパイラはなぜ私がTableLayoutにIDを与えていないと言っていますか?
IOW:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ondemandandautomatic_dynamicauthorize); <-- crashes when I F6 (Eclipse) on this line
...だから、私は私のXMLレイアウトファイルに警告アイコンに気づいた: "このTableLayoutは無用です(子を持たない、背景なし、ノーID)"
まあ私は実行時に子を追加するつもりです。なぜそれは背景が必要ですか?そして、大きな疑問:なぜそれは私が1を追加しました何のIDを、持っていないと言うん:
<TableLayout>
android:id="@id/tlDynamicRows" <-- IT'S RIGHT THERE!!!
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
「これのTableRowまたはそののTableRowの親は無用である」、と言うの別の警告がありますこの不快な開発を引き起こしている可能性が何
<?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>
:
ここでは全体のxmlですか?
更新日:
私のポストを見ている、私は、XMLの最後の「TableLayoutは」余分直角ブラケットを持っていたことがわかりました。だから、私は最初のものを取り出しました、そして今、私はエラーメッセージを取得します。 "指定された名前と一致するリソースが見つかりませんでした(値 '@ id/tlDynamicRows'の 'id')。
<TableLayout
android:id="@id/tlDynamicRows"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
与えるもの:XMLの一部が今していることを
?
アップデート:ここで
が最終的に作品の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
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>
私はまだScrollView内部TableLayoutにこの行を変更するには、警告メッセージを持っていた:
android:layout_height="wrap_content"
へ:
android:layout_height="wrap_content"
私はやったが、違いはないようだが、警告を消してしまったので残しておきます。
"+" これらのすべてを削除すると、エラーメッセージが3つの要素で表示されます。この: アンドロイド:ID = "@ ID/scrollViewHost" はこれを与える: エラー:エラー:いいえリソースは、それが( 'ID/scrollViewHost @' の値 で 'ID' で)指定された名前と一致していません。 ... @ id/tlDynamicと@ id/tlDynamicRowsについても同様です。 "+"を追加し、TableRowのlayout_widthとlayout_heightプロパティを含めた後、最終的に動作します。私は後世のために上記の新しいXMLを追加しました。 –
私はまだこのTableRorのレイアウトやTableLayoutの親は役に立たないと思っていますが、私がしたいことをまさにやっています。 –
@ClayShannon ..このリンクはテーブルレイアウトの理解に役立ちます。 ..http://developer.android.com/reference/android/widget/TableLayout.html –