別のレイアウトで子レイアウトを複数回再利用するアプリを開発しています。
私の子レイアウトにはボタンが1つしかありません。
私の質問は..子レイアウトのビューに別の方法でアクセスするにはどうすればよいですか。
たとえば、親レイアウトで子レイアウトに3回アクセスします。次に、実行時に親レイアウトに 3 つのボタンを表示します。これらのボタンからさまざまなアクティビティを呼び出したいです。
My child layout
<RelativeLayout
android:id="@+id/mylayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="30dp"
android:orientation="horizontal" >
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/chemistry" />
</RelativeLayout>
My Parent Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_bg" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="470dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lol"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
Java Code--
LinearLayout rl= (LinearLayout)findViewById(R.id.lol);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
ArrayList<String> as= getIntent().getExtras().getStringArrayList("dis");
Object[] mstring= as.toArray();
int x= mstring.length;
for (int i=0;i<x; i++ ){
View childLayout = inflater.inflate(R.layout.despage,
(ViewGroup) findViewById(R.layout.despage));
rl.addView(childLayout);