L
LoLmAnxD1998
Ambitioniertes Mitglied
- 0
Hallo Comunity,
Ich habe in meiner App ein LinearLayout indem sich weitere LinearLayouts und ImageButtons befinden. Ich versuche jetzt mit folgendem Code die ImageResourcen der einzelnen Buttons zu ändern:
Leider funktioniert das nicht, da sich auch die anderen Layouts darin befinden und die sich logischer weise nicht zu ImageButtons casten lassen. Hat jemand eine Idee wie ich das machen kann ? Hier mein Layout XML:
Ich habe in meiner App ein LinearLayout indem sich weitere LinearLayouts und ImageButtons befinden. Ich versuche jetzt mit folgendem Code die ImageResourcen der einzelnen Buttons zu ändern:
Code:
int nummer = 0;
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
while (nummer < mainLayout.getChildCount()){
ImageButton button = (ImageButton)mainLayout.getChildAt(nummer);
int type = (Integer) button.getTag(R.id.ctype);
if (type == 1){
button.setImageResource(R.drawable.img_1);
}
if (type == 2){
button.setImageResource(R.drawable.img_2);
}
}
Leider funktioniert das nicht, da sich auch die anderen Layouts darin befinden und die sich logischer weise nicht zu ImageButtons casten lassen. Hat jemand eine Idee wie ich das machen kann ? Hier mein Layout XML:
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="6"
android:id="@+id/mainLayout" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="3" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="3" >
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="3" >
<ImageButton
android:id="@+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
<ImageButton
android:id="@+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>