2013-02-25 13 views
6

द्वारा AlertDialog शीर्षक जाओ मैं जब मैं गतिविधि मैं tit के लिए 02-25 17:59:04.759: E/AndroidRuntime(1014): java.lang.NullPointerException था जब टाइपफेस सेट में फ़ंक्शन को कॉल इस समारोहfindViewById

private void saveDialog(){ 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle(res.getString(R.string.dialog_title)) 
       .setMessage(res.getString(R.string.dialog_saveconfirm)) 
       .setCancelable(false) 
       .setNegativeButton(res.getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
       } 
       }) 
       .setPositiveButton(res.getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        //do some thing 
      }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 

     TextView tit = (TextView) alert.findViewById(android.R.id.title); 
     TextView msg = (TextView) alert.findViewById(android.R.id.message); 
     Button btn2 = alert.getButton(DialogInterface.BUTTON_NEGATIVE); 
     Button btn1 = alert.getButton(DialogInterface.BUTTON_POSITIVE); 
     tit.setTypeface(UtiliShare.getTf()); 
     msg.setTypeface(UtiliShare.getTf()); 
     btn1.setTypeface(UtiliShare.getTf()); 
     btn2.setTypeface(UtiliShare.getTf()); 

} 

इस्तेमाल किया द्वारा AlertDialog फ़ॉन्ट बदलने की कोशिश की लेकिन जब मैं tit संवाद काम अच्छा हटा दें।

मुझे लगता है कि TextView tit = (TextView) alert.findViewById(android.R.id.title); में त्रुटि यह शून्य है।

मैं इसे कैसे हल कर सकता हूं ??


अद्यतन यह लिंक मेरे सवाल का जवाब शामिल Answer

Sam

+0

पर एक नज़र मैं एंड्रॉयड आइए विश्वास नहीं करते आप इस तरह इन TextViews उपयोग कर सकते है, लेकिन आप शैलियों और विषय-वस्तु का उपयोग करने के आप क्या चाहते हैं करने के लिए सक्षम होना चाहिए: [AlertDialog की शैली बदलें] (http://stackoverflow.com/q/8011899/1267661) – Sam

+0

मेरी पोस्ट यहां आपकी सहायता कर सकती है http://stackoverflow.com/questions/4025605/custom-dialog-on-android-how-can-i-center-its -टाइटल/13359573 # 13359573 " –

+2

हम्म, यह उत्तर दावा करता है कि आप 'शीर्षक' के बजाय 'चेतावनी टिटल' का उपयोग कर सकते हैं: [फ़ॉन्ट आकार को अलर्टडियलॉग में बदलना] (http://stackoverflow.com/a/9183354/1267661)। (मैंने इसे स्वयं नहीं किया है।) – Sam

उत्तर

1

आदेश textviews जिस तरह से आप चाहते हैं बदलने के लिए में करने के लिए धन्यवाद, मैं संवाद के लिए एक कस्टम लेआउट का उपयोग करना चाहिये था ।

http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

+0

सैम टिप्पणी देखें। धन्यवाद। – AwadKab

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