Android empty Linear layout contents

Manoharan picture Manoharan · Mar 8, 2012 · Viewed 31.4k times · Source

H have multiple TextViews inside an LinearLayout. Now I want to delete this text view in java. The views are generated dynamically. How can I empty all contents inside this LinearLayout?

<LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/myid">

    <TextView .../>
    <TextView .../>
    <TextView .../>

</LinearLayout>

Answer

Ted Hopp picture Ted Hopp · Mar 8, 2012

You can use this:

LinearLayout ll = (LinearLayout) findViewById(R.id.myid);
ll.removeAllViews();