2012-08-13 8 views
7

Mi pregunta es ¿cuál es la mejor manera de crear una instancia de LayoutInflater? ¿Hay alguna diferencia entreCreación eficiente de un LayoutInflater

LayoutInflater inflater = LayoutInflater.from(context); 

y

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

Cuál es la mejor solución? Otras soluciones también son bienvenidas.

Gracias.

Respuesta

10

Si marcó el archivo fuente LayoutInflater.java que encontrará.

/** 
* 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; 
} 
+1

Por lo que la segunda solución debe ser un poco eficiente que la Primera. –

+0

Derecha. Gracias. – overbet13