27

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

1
  • What type of Object do you mean? If you just want a handle to an XML defined GUI object, why not just use findViewById(id)? Commented Dec 12, 2011 at 22:22

3 Answers 3

50

You should change your line to:

LayoutInflater.from(context).inflate(R.layout.myfile, null);

You can find it in documentation here.

Sign up to request clarification or add additional context in comments.

Comments

6
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

Comments

-6

You could make this component invisible with:

android:visibility="gone"

Source: http://developer.android.com/reference/android/view/View.html#attr_android:visibility

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.