android對話框應用 – Android移動開發技術文章_手機開發 Android移動開發教學課程

啥都別說瞭,看效果吧!
1代碼 
new AlertDialog.Builder(Lesson_01_Pic.this).setTitle(“提示標題”).setMessage(“這是提示內容”).show();    
 
2代碼 
new AlertDialog.Builder(Lesson_01_Pic.this)   
         .setTitle(“這是標題”)   
        .setMessage(“這是提示內容”)    
        .setPositiveButton(“確定”,    
        new DialogInterface.OnClickListener(){   
                  public void onClick(DialogInterface dialoginterface, int i){    
                                 //按鈕事件    
                           Toast.makeText(Lesson_01_Pic.this, “確定”,Toast.LENGTH_LONG).show();   
                              }    
                     }).show();    
 
3代碼 
import android.app.Activity;   
 import android.app.AlertDialog;   
 import android.app.Dialog;   
 import android.content.DialogInterface;   
 import android.content.DialogInterface.OnClickListener;   
 import android.content.DialogInterface.OnMultiChoiceClickListener;   
 import android.os.Bundle;   
 import android.view.View;   
 import android.widget.Button;   
 import android.widget.Toast;   
 public class Lesson_02_Dia extends Activity {   
     /** Called when the activity is first created. */   
     @Override   
     public void onCreate(Bundle savedInstanceState) {   
         super.onCreate(savedInstanceState);   
         setContentView(R.layout.main);   
            
         Button button = (Button)findViewById(R.id.b01);   
         button.setText(“對話框”);   
         button.setOnClickListener(new Button.OnClickListener(){   
             @Override   
             public void onClick(View v) {   
                 //選項數組   
                 String[] choices={“Facebook”,”Twitter”};   
                 //Check判斷數組,與選項對應   
                 boolean[] chsBool = {true,false};   
                  //包含多個選項及復選框的對話框   
                 AlertDialog dialog = new AlertDialog.Builder(Lesson_02_Dia.this)   
                          .setIcon(android.R.drawable.btn_star_big_on)   
                          .setTitle(“調查”)   
                          .setMultiChoiceItems(choices, chsBool, multiClick)   
                          .setPositiveButton(“Yes”, onclick)   
                          .setNegativeButton(“No”,  onclick).create();   
                 dialog.show();   
             }   
                
         });   
     }   
       
     /**  
      * 對話框復選框事件監聽器  
     */   
   OnMultiChoiceClickListener multiClick = new OnMultiChoiceClickListener(){   
         @Override   
         public void onClick(DialogInterface dialog, int which, boolean isChecked) {   
             Toast.makeText(Lesson_02_Dia.this, “第”+(which+1)+”項,選中結果:”+isChecked,Toast.LENGTH_SHORT).show();   
         }   
            
     };   
        
     /**  
     * 對話框按鈕點擊事件監聽器  
      */   
     OnClickListener onclick = new OnClickListener() {   
         @Override   
         public void onClick(DialogInterface dialog, int which) {   
            switch (which) {   
                 case Dialog.BUTTON_NEGATIVE:   
                     Toast.makeText(Lesson_02_Dia.this, “No..”,   
               &nbs

You May Also Like