Mellon Mellon - 1 year ago 122
Android Question

Check if view element is added to layout or not programmatically

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?

Answer Source

I think you can simply use


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download