Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently creating a LayoutInflater

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.

like image 288
overbet13 Avatar asked Aug 13 '12 12:08

overbet13


1 Answers

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;
}
like image 55
Jug6ernaut Avatar answered Oct 11 '22 11:10

Jug6ernaut