tags:

views:

65

answers:

2

Hi All!

Can anybody please tell What Inflator is and how it is being used in the Android Application?

I don't know the exactn use of it and Why It is being used.

Thnaks, david

+1  A: 

Not quite sure what you mean, but if its related with inflating views, its used to load layout xml files into your application. e.g by

View myWelcome = View.inflate(this, R.layout.welcome, null);

Its easier and consider best practice to have you view definition inside layout xml files, instead of creating your views fully by code.

PHP_Jedi
+1  A: 

My preferred way to handle inflation:

//First get our inflater ready, you'll need the application/activity context for this
LayoutInflater mInflater;
mInflater = LayoutInflater.from(mContext);

//Inflate the view from xml
View newView = mInflater.inflate(R.layout.my_new_layout, null);

//Then you'll want to add it to an existing layout object
mMainLayout.add(newView);

//Or perhaps just set it as the main view (though this method can also 
// inflate the XML for you if you give it the resource id directly)
setContentView(newView);

Basically, you use it to inflate existing xml layouts at runtime. Usually you go ahead and insert those new views into previously defined ViewGroups or List objects.

Marloke