2011-06-06 20 views
17

मैं बटन प्रेसएंड्रॉयड पास कस्टम संवाद

 //set up dialog 
     Dialog dialog = new Dialog(BrowseActivity.this); 
     dialog.setContentView(R.layout.about); 
     dialog.setTitle("This is my custom dialog box"); 
     dialog.setCancelable(true); 
     //there are a lot of settings, for dialog, check them all out! 

     //set up text 
     TextView text = (TextView) dialog.findViewById(R.id.TextView01); 
     text.setText(R.string.app_help_message); 

     //set up image view 
     ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01); 
     img.setImageResource(R.drawable.icon); 

     //set up button 
     Button button = (Button) dialog.findViewById(R.id.Button01); 
     button.setOnClickListener(new View.OnClickListener() { 
     @Override 
      public void onClick(View v) { 
      Dialog.dismiss(); 

      } 
     }); 

     //now that the dialog is set up, it's time to show it  
     dialog.show(); 

     return true; 

dialog.dismiss मेरे लिए काम नहीं कर रहा है पर बंद करने के लिए कस्टम संवाद पाने के लिए कोशिश कर रहा हूँ। मैं बस एक कस्टम स्क्रीन के रूप में इस कस्टम संवाद का उपयोग करने की कोशिश कर रहा हूं और इसे बंद करने के लिए बटन दबाएं।

मैं बहुत एंड्रॉयड देव के लिए नया हूँ, लेकिन कई कई घंटों के लिए इस कोशिश कर रहे हैं

धन्यवाद किसी भी सलाह देने के लिए

+0

आपको डायलॉग क्लास पर डायलॉग डायलॉग = नया संवाद (ब्राउज़ एक्टिविटी.थिस) का उपयोग करके संवाद उदाहरण पर खारिज करने की आवश्यकता है। –

उत्तर

31
final Dialog dialog = new Dialog(BrowseActivity.this); 

आप लोअरकेस संवाद की जरूरत है।

public void onClick(View v) { 
    dialog.dismiss(); 
} 

भी AlertDialog.Builder आपके लिए बेहतर विकल्प हो सकता है।

+0

अच्छी तरह से समस्या हल करने के लिए, मैंने AlertDialog.Builder का उपयोग किया है स्क्रीन लेकिन इसके बारे में पता नहीं लगा सका कि इसके लिए एक लेआउट कैसे सेट करें। जैसा कि मैंने कहा, यह मेरे लिए बिल्कुल नया है और मुझे हैरान है कि मुझे यह मिल गया है। मैं और पढ़ूंगा – user639410

2

आप खारिज कर सकते हैं(); संवाद पर यह मेरे लिए काम करता है।

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