2012-08-13 16 views
7

मेरा प्रश्न यह है कि LayoutInflater उदाहरण बनाने का सबसे अच्छा तरीका क्या है? वहाँकुशलता से एक लेआउट इन्फ्लूटर

LayoutInflater inflater = LayoutInflater.from(context); 

और

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

कौन सा बेहतर समाधान है के बीच कोई अंतर है? अन्य समाधान भी स्वागत है।

धन्यवाद।

उत्तर

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

तो दूसरा समाधान पहले की तुलना में थोड़ा कुशल होना चाहिए। –

+0

दाएं। धन्यवाद। – overbet13

संबंधित मुद्दे