ループを使用してレイアウトを複数回膨らませて、別のレイアウトにしたい。TextViewまたはその他の単一のビューを拡張する場合、Javaは問題ありません。しかし、私はこのレイアウト全体を膨らませたいです。次のコードは機能しないため、これにはどの方法を使用しますか。(私が言ったように、ループとすべては問題ありません、それはレイアウト全体を膨らませることができません。私は単純なビューを膨らませる方法しか知りません)。
View childInflatedView = (View) theInflater.inflate(R.id.restaurant_displayed_on_list, null);
linLayout.addView(childInflatedView);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:background="@drawable/gradient_bg_hover"
android:id="@+id/restaurant_displayed_on_list" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dp"
android:layout_weight="6"
android:layout_height="fill_parent"
android:text="this is the inflated text"
android:textColor="#990099"
android:textSize="20dp"
android:gravity="center_horizontal"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background= "@drawable/delete"
/>
</LinearLayout>
編集1:
Matthewが述べたように、解決策はレイアウトリソースIDによってレイアウトを膨らませることだと思います。レイアウトをTextViewにキャストできないため、上記に示されていないこのコード行に問題があると思います。
View categoryInflatedView1 = (View) theInflater.inflate(R.layout.categories_available, null);
((TextView) categoryInflatedView1).setText(category1);
linLayout.addView(categoryInflatedView1);
レイアウト内にあるTextViewにアクセスするにはどうすればよいですか。膨らませる前にテキストビューを編集する必要があります。