android對話方塊應用

來源:互聯網
上載者:User

啥都別說了,看效果吧!
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.