3 回答
TA贡献1784条经验 获得超2个赞
您removeViewAt与索引一起使用
final LinearLayout mLayout=findViewById(R.id.linearLayout)
mLayout.removeViewAt(mLayout.getChildCount()-1); // get the last view
//or using index counter variable
//mLayout.removeViewAt(ArraySize-1); // adjust the value accordingly
或者您可以使用removeView获取视图并删除它
final LinearLayout mLayout=findViewById(R.id.linearLayout)
View v = mLayout.getChildAt(mLayout.getChildCount()-1);
mLayout.removeView(v);
TA贡献1856条经验 获得超17个赞
您可以在此路径 res/values/ids.xml 中创建一个 XML 文件;
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="view_1" type="id"/>
</resources>
然后在 Java 中添加 id,就像这样
textView.setId(R.id.view_1);
当你想删除它时
LinearLayout mLayout=findViewById(R.id.linearLayout);//to find in this specific view
TextView textView = (TextView)mLayout.findViewById(R.id.view_1);
mLayout.removeView(textView);
添加回答
举报