7

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

LayoutInflater inflater = LayoutInflater.from(context);

and

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

Which is the better solution? Other solutions are also welcome.

Thanks.

overbet13
  • 1,654
  • 1
  • 20
  • 36

1 Answers1

10

If you checked the LayoutInflater.java source file you would 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;
}
Jug6ernaut
  • 8,219
  • 2
  • 26
  • 26