检查视图元素是否已添加到布局或是否以编程方式添加 [英] Check if view element is added to layout or not programmatically

查看:67
本文介绍了检查视图元素是否已添加到布局或是否以编程方式添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在片段类中,我有条件地将子视图元素以编程方式添加到布局中:

In my fragment class, I add a child view element programmatically to my layout conditionally :

LinearLayout child = (LinearLayout) inflater.inflate(R.layout.child_view, null);

LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,100);

container.addView(child, params);

由于上面的代码将有条件地运行,因此,在某个时候,我想检查子视图是否已添加,如何通过编程方式进行检查?

Since the above code will be run conditionally, so, at some point, I would like to check if the child view has added or not, how to make this checking programmatically?

推荐答案

我认为您可以简单地使用

I think you can simply use

findViewById(your_view_id) 

方法:如果结果为null,则该视图不存在,否则该视图存在

method: If its result is null the view does not exists, otherwise the view is present

这篇关于检查视图元素是否已添加到布局或是否以编程方式添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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