安卓空线性布局内容

61

我有多个TextViews,它们都在一个LinearLayout里面。现在我想用Java代码删除这个TextViews。这些视图是动态生成的。如何清空该LinearLayout内的所有内容?

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

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

</LinearLayout>
1个回答

160

你可以使用这个:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接