Efficient LayoutInflater Creation

My question is the best way to create an instance of LayoutInflater ? Is there any difference between

 LayoutInflater inflater = LayoutInflater.from(context); 

and

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

What is the best solution? Other solutions are also welcome.

Thanks.

+7
source share
1 answer

If you checked the source file LayoutInflater.java, you will find.

 /** * Obtains the LayoutInflater from the given context. */ public static LayoutInflater from(Context context) { LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { throw new AssertionError("LayoutInflater not found."); } return LayoutInflater; } 
+10
source

All Articles