I’m still very new to Android, but I am trying to keep up by using tutorials on YouTube. A bunch of people throw around the phrase “inflate the xml”. I started to use this phrase as well, and I feel as though I’m not doing it right.
The only time I say “inflate the xml” is when telling someone to write the code to use a widget from the xml in java code.
So if I see a button on someones layout, with the id of button01, and I tell them to “inflate the xml” I expect Button mybutton = (Button) findViewById(R.id.button01);
Is this wrong of me?
EDIT:
It seems as though this is not the correct phrase. Does one exist?
“Inflating” a layout refers to the process of having the Android framework convert a layout in XML format into objects corresponding to the different views in the layout.
To “inflate” a layout you need:
a layout in XML format
res/layout/main.xml
access to an inflator object
LayoutInflater inflater =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
You then need to run the inflation on the layout
After that you can access the objects using “findViewById”
The Activity class provides a helper method which both gets the inflator and inflates the layout
When using the “setContentView” method, the activity sets a default view which is used when calling “findViewById”