In my fragment class, I add a child view element programmatically to my layout conditionally :
LinearLayout child = (LinearLayout) inflater.inflate(R.layout.
If you creating view via inflater, you can check his parent
if(view.getParent() != null) {...}