7

LayoutInflater私の質問は、インスタンスを作成する最良の方法は何ですか? 間に違いはありますか

LayoutInflater inflater = LayoutInflater.from(context);

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

より良い解決策はどれですか? 他のソリューションも大歓迎です。

ありがとう。

4

1 に答える 1

10

LayoutInflater.java ソース ファイルを確認すると、見つかります。

/**
 * 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;
}
于 2012-08-13T13:04:04.400 に答える