Efficiently creating a LayoutInflater
Asked Answered
I

1

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.

Iffy answered 13/8, 2012 at 12:48 Comment(0)
N
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;
}
Noam answered 13/8, 2012 at 13:4 Comment(1)
So the second solution should be a little efficient than the First One.Raddi

© 2022 - 2024 — McMap. All rights reserved.