Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> Android詳細的對話框AlertDialog.Builder使用方法

Android詳細的對話框AlertDialog.Builder使用方法

編輯:初級開發

package com.jar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.VIEw;
import android.view.VIEw.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageVIEw;
import android.widget.Toast;

public class Demo1 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
     Button b1;
        super.onCreate(savedInstanceState);
        setContentVIEw(R.layout.main);
        b1=(Button)findVIEwById(R.id.b1);
//        new AlertDialog.Builder(Demo1.this) 
//        .setTitle("請選擇") 
//        .setIcon(android.R.drawable.ic_dialog_info)                 
//        .setSingleChoiceItems(new String[] {"選項1","選項2","選項3","選項4"}, 0,  
//          new DialogInterface.OnClickListener() {                                      
//             public void onClick(DialogInterface dialog, int which) { 
//                dialog.dismiss(); 
//             } 
//          } 
//        ) 
//        .setNegativeButton("取消", null) 
//        .show();
        
        
        
        
//        new AlertDialog.Builder(Demo1.this) 
//        .setTitle("請輸入") 
//        .setIcon(android.R.drawable.ic_dialog_info) 
//        .setVIEw(new EditText(Demo1.this)) 
//        .setPositiveButton("確定", null) 
//        .setNegativeButton("取消", null) 
//        .show(); 
        
        
        ImageView img = new ImageVIEw(Demo1.this); 
        img.setImageResource(R.drawable.icon); 
      
        new AlertDialog.Builder(Demo1.this) 
        .setTitle("多選框") 
//        .setItems(new String[] {"列表項1","列表項2","列表項3"}, null)
//        .setMultiChoiceItems(new String[] {"選項1","選項2","選項3","選項4"}, null, null) 
        .setVIEw(img)
        .setIcon(android.R.drawable.ic_lock_silent_mode_off)
        .setPositiveButton("確定", null)                 
        .setNegativeButton("取消", null) 
        .show(); 
        b1.setOnClickListener(new OnclickListener());
        
    }
    class OnclickListener implements OnClickListener{

  public void onClick(VIEw v) {
   // TODO Auto-generated method stub
   AlertDialog.Builder ab = new AlertDialog.Builder(Demo1.this); 
         ab.setTitle("請選擇"); 
         ab.setIcon(android.R.drawable.ic_dialog_info);                 
         ab.setSingleChoiceItems(new String[] {"選項1","選項2","選項3","選項4"}, 0,  
           new DialogInterface.OnClickListener() {                                      
              public void onClick(DialogInterface dialog, int which) { 
                 dialog.dismiss(); 
              } 
           } 
         ); 
         ab.setNegativeButton("取消", null); 
         ab.show();
  }
     
    }
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved