Answer the question
In order to leave comments, you need to log in
Android: LayoutInflater - why is it needed?
Good afternoon!
I started to study Android and now I came to the topic about LayoutInflater. No matter how much I searched for explanations in Google Search and in the books of various writers, I still couldn’t understand: what is this thing? And why not use the shorter findViewById instead? After all, they both take an element (any View) from the xml file in order to work in the code.
Answer the question
In order to leave comments, you need to log in
The LayoutInflater class contains a method:
public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
if (DEBUG) System.out.println("INFLATING from resource: " + resource);
XmlResourceParser parser = getContext().getResources().getLayout(resource);
try {
return inflate(parser, root, attachToRoot);
} finally {
parser.close();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question