Reputation: 4074
I only want to get an object from a xml layout file without having to implement it into the current layout.
I know the way with
LayoutInflater.from(context).inflate(R.layout.myfile, myparent, true);
but after execution of the above the layout will be implemented and shown immediately inside my "myparent"-View, right? I only want to get the Object itself to get its attributes and such. And maybe (but only maybe) insert it later into the shown layout. Is that possible?
Regards
Upvotes: 27
Views: 33101
Reputation: 10938
LayoutInflater.from(context).inflate(R.layout.myfile, myparent, true);
The end parameter determines whether or not to automatically add the new view to myparent. Turn it to false to still use the parent's layout attributes.
Or, if you don't care about the parent's layout params, follow @inazaruk's answer
Upvotes: 6
Reputation: 2817
You could make this component invisible with:
android:visibility="gone"
Source: http://developer.android.com/reference/android/view/View.html#attr_android:visibility
Upvotes: -6