यह एक नोब सवाल हो सकता है, लेकिन मैं सोच रहा था कि हमें टोस्ट बनाने के लिए एक स्थिर विधि (मेकटेक्स्ट) का उपयोग क्यों करना है, न कि कन्स्ट्रक्टर। इस के बजायक्यों टोस्ट.मेकटेक्स्ट और नया टोस्ट नहीं
makeText(Context context, CharSequence text, int duration)
:
क्यों हम इस का उपयोग करने की क्या ज़रूरत है
new Toast(Context context, CharSequence text, int duration)
यह makeText विधि है:
public static Toast makeText(Context context, CharSequence text, int duration) {
Toast result = new Toast(context);
LayoutInflater inflate = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
result.mNextView = v;
result.mDuration = duration;
return result;
}
हम क्यों नहीं है निम्नलिखित:
public Toast (Context context, CharSequence text, int duration) {
this(context);
LayoutInflater inflate = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView)v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
this.mNextView = v;
this.mDuration = duration;
}
मैंने किसी भी कारण से वेब और स्रोत कोड की खोज की लेकिन मुझे नहीं मिला।
यदि आपके पास कोई विचार है, तो संकोच न करें।
शायद क्योंकि एक स्थिर विधि का उपयोग करना आसान है और हमें टोस्ट ऑब्जेक्ट बनाने की ज़रूरत नहीं है? :) – Slickelito