2013-01-13 42 views
0

reference link下面兩條線都做相同。Android LayoutInflater

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

我不知道哪條路是正確的或正確的。有人可以指出我有什麼不同。

回答

1

正如你所說,它們是等價的。 LayoutInflater.from(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; 
} 
+0

非常感謝你 –

0

這是正確的,從另一個類獲取數據

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

太謝謝你了 –