ViewGroup removeAllViews

R

RaRu

Neues Mitglied
0
Guten Tach!

Ich habe ein linearLayout welches u.a. noch ein linearLayout enthält.
Wenn ich nun auf das zweite (sub)linearLayout ein removeAllViews() mache, sollte dies eigentlich alle Buttons darin entfernen. Leider wird aber auch der Inhalt des parent linearLayout gelöscht, also quasi alles.

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Layout01" 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/white">
<TextView  
    android:id="@+id/TextView01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/textcolor"/>
<ImageView 
    android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
<LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />
</LinearLayout>

Code:
[...]
setContentView(R.layout.main);

imgView = (ImageView) findViewById(R.id.ImageView01);
subLinearLayout = (android.widget.LinearLayout) findViewById(R.id.Layout01);
[...]
// fülle das sublinearlayout
[...]
subLinearLayout.removeAllViews();

Ist sicher ein einfacher Fehler, oder? ;-) Hilfe!
 
RaRu schrieb:
Guten Tach!

Ich habe ein linearLayout welches u.a. noch ein linearLayout enthält.
Wenn ich nun auf das zweite (sub)linearLayout ein removeAllViews() mache, sollte dies eigentlich alle Buttons darin entfernen. Leider wird aber auch der Inhalt des parent linearLayout gelöscht, also quasi alles.

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="[COLOR=Red]@+id/Layout01"[/COLOR] 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/white">
<TextView  
    android:id="@+id/TextView01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="@color/textcolor"/>
<ImageView 
    android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>
<LinearLayout 
    android:id="[COLOR=Red]@+id/LinearLayout01[/COLOR]" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />
</LinearLayout>
Code:
[...]
setContentView(R.layout.main);

imgView = (ImageView) findViewById(R.id.ImageView01);
subLinearLayout = (android.widget.LinearLayout) findViewById([COLOR=Red]R.id.Layout01[/COLOR]);
[...]
// fülle das sublinearlayout
[...]
subLinearLayout.removeAllViews();
Ist sicher ein einfacher Fehler, oder? ;-) Hilfe!

Ich vermute mal dein XML Code ist unvollständig oder? Sonst hättest du weder Buttons, noch ein subLayout, das irgendwelche Elemente besitzt. Wenn dem so ist, und da in Wirklichkeit noch mehr steht, würde ich sagen du hast deinem subLinearLayout Objekt die ID des parentLayout übergeben :)

Gruß
 
  • Danke
Reaktionen: RaRu
Hey Iblis,

danke für deine Hilfe! Da war ich wohl zu flüchtig, eigentlich hatte ich genau diese Fehlerquelle geprüft, aber die IDs dann wohl vertauscht.

Nun funktioniert es...

Die Buttons generiere ich übrigens zur Laufzeit.
 

Ähnliche Themen

F
  • Flocke123
Antworten
3
Aufrufe
634
amfa
A
M
Antworten
3
Aufrufe
1.094
MandraKobold
M
T
Antworten
0
Aufrufe
965
Terth
T
Zurück
Oben Unten