删除里面的LinearLayout的所有项目 [英] Remove all items inside linearlayout

查看:220
本文介绍了删除里面的LinearLayout的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的LinearLayout的refes到XML项目。这里面的LinearLayout我把一些TextView的动态,所以没有从XML服用。现在,我需要从LinearLayout中删除这些textviews。我想这样的:

I create a linearlayout that refes to an xml item. Inside this linearlayout i put some textview dynamically, so without taking them from the xml. Now i need to remove these textviews from the linearlayout. I tried this:

if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0)
    ((LinearLayout) linearLayout.getParent()).removeAllViews();

,但它不工作。 我能怎么做? 谢谢,马蒂亚

but it doesn't work. How can i do? Thanks, Mattia

推荐答案

为什么要这么写 linearLayout.getParent()你应该做的这一切直接的LinearLayout

Why you wrote linearLayout.getParent() you should do all this directly on LinearLayout

if(((LinearLayout) linearLayout).getChildCount() > 0) 
    ((LinearLayout) linearLayout).removeAllViews(); 

这篇关于删除里面的LinearLayout的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆