Aplit
Aplit

Reputation: 71

getView Inflater

This may be an elementary question, but I just want to know: When initializing the Inflater inside the getView() method, what's the different between these lines:

convertView = inflater.inflate(resource, root);
convertView = View.inflate(context, resource, root);

Follow-up question: Which is best to use in initializing the Inflater? Thanks for any response.

Upvotes: 0

Views: 1298

Answers (1)

Vinay S Shenoy
Vinay S Shenoy

Reputation: 4028

The View#inflate() method will take care of retrieving the LayoutInflater from the Context for you, while the former method will use an inflater method you fetched.

If you have to inflate a view just once, you can use the View#inflate() method as it is more convenient.

If you are inflating the views in an adapter, however, since you have to repeatedly inflate views, it would be better to get the LayoutInflater object just once(In the constructor of your adapter, pass the Activity context or the LayoutInflater object) and reuse that same inflater object in your getView().

Upvotes: 1

Related Questions