मैं इस कोड का उपयोगएंड्रॉयड कस्टम टोस्ट
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast));
TextView text = (TextView) layout.findViewById(R.id.toast_tv);
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
हालांकि, बाद से मैं LayoutInflater
के प्रयोजन के समझ में नहीं आता कस्टम टोस्ट बनाने के लिए कर रहा था, मैं इस के लिए कोड ... संशोधित
Toast toast = new Toast(getApplicationContext());
toast.setView(findViewById(R.id.custom_toast));
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
और मैं RuntimeException कहा, "setview चाहिए बुलाया गया है" मिल ..
क्यों मैं सिर्फ नहीं कर सकते
LayoutInflater
का उपयोग किए बिना टोस्ट को दृश्य असाइन करें?सामान्य रूप से
LayoutInflater
का उद्देश्य क्या है ताकि मैं इस अनुभव को अन्य कस्टम विचारों पर लागू कर सकूं?
संपादित करें: मैं onListItemClick()
इंटरफ़ेस विधि .. सामग्री सेट होने के बाद में इन कोड का उपयोग कर रहा ..
मुझे लगता है कि एक अच्छा सवाल "लेआउट इन्फ्लेटर आंतरिक रूप से क्या करता है"? – Behnam