Looking at the Android tutorial on:
http://developer.android.com/guide/topics/fundamentals/fragments.html
… it seems fragments have their layouts defined programmatically. Is there a way to use the usual XML files instead?
Thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You just missed it, this is the first code snippet in the fragment documentation:
It uses a (supplied)
LayoutInflaterto inflate a layout, in this case namedexample_fragment.xml(inflate means parse XML and generate a layout structure out of it). So yes, certainly possible.Basically all you have to do is return your fragment layout from
onCreateView(). How you generate it inside is up to you, and since you get an inflater supplied, it’s intended to use XML too.