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?
maybe you can try this
or this one
I think you can simply use
method: If its result is null the view does not exists, otherwise the view is present
Sorry for late reply but you may try this alternative:
use
container.getChildCount();
before adding and after adding a view. Like :Or if you have a view instance to find, you could:
I cannot write a comment so I write it here as a solution: From API level 19 you can call
isAttachedToWindow()
which doesn't help a lot, but if you are aimingAPI 19
or higher, then this should work by the documentation.If you creating view via inflater, you can check his parent