What is the difference between cheaters

What is the difference between execution

LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

and inflater = LayoutInflater.from(activity);

+4
source share
1 answer

What is the difference between inflatables

The difference is that in the second example (via the static method) you do not need to throw the Object into the LayoutInflater , because it returns directly an instance of the LayoutInflater.

The first case usually returns an Object, which you must explicitly pass to the LayoutInflater . But the result of both methods is a new instance of LayoutInflater

It is up to you which method you choose. I usually use the LayoutInflater.from(); method LayoutInflater.from(); and have no problems. I do not need to throw from Object, and this will do the trick.

As mentioned in @CommonsWare, you can also call

 getLayoutInflater() 

If you are in an Activity class (this is an Activity method). But when you are not in Activity, you need to have a Context variable, and then you can call (for example, from a list):

 ((Activity) context).getLayoutInflater(); 

But I think that when you are not in Activity, it is much easier and more efficient to call LayoutInflater.from(); instead of the above approaches.

+5
source

All Articles