中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android開發:對話框

發布時間:2020-07-03 08:29:10 來源:網絡 閱讀:465 作者:斯萊特林 欄目:移動開發
package com.xy.alterdialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
public class Main extends Activity {
    private Button btn;
    private Button btn2;
    private Button btn3;
    private Button btn4;
      
    private final CharSequence[] items = {"北京","上海","廣州"};
      
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alterdialog);
          
        btn = (Button)findViewById(R.id.button1);
        btn2 = (Button)findViewById(R.id.button2);
        btn3 = (Button)findViewById(R.id.button3);
        btn4 = (Button)findViewById(R.id.button4);
          
        //AlterDialog
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);  
                builder.setMessage("Sure to Cancel?");
                builder.create();
                builder.setPositiveButton("Yes", new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                builder.setNegativeButton("No", new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
      
        //列表對話框
        btn2.setOnClickListener(new View.OnClickListener() {
              
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                builder.setTitle("提示");
                builder.setItems(items, new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                          
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
          
        //單選對話框
        btn3.setOnClickListener(new View.OnClickListener() {
              
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                builder.setTitle("請選擇");
                builder.setSingleChoiceItems(items, -1, new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                          
                    }
                });
                AlertDialog dialog = builder.create();
                builder.setPositiveButton("確定", new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                          
                    }
                });
                builder.show();
            }
        });
          
        //復選對話框
        btn4.setOnClickListener(new View.OnClickListener() {
              
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                builder.setTitle("請選擇");
                //第二個參數null:默認開始時沒有被選中的選項
                builder.setMultiChoiceItems(items, null, new OnMultiChoiceClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface dialog, int which,boolean isChecked) {
                        // TODO Auto-generated method stub
                          
                    }
                });
                builder.setPositiveButton("確定", new OnClickListener() {
                      
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                          
                    }
                });
                  
                AlertDialog dialog = builder.create();
                dialog.show(); 
            }
        });
          
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宁都县| 怀集县| 丰都县| 化德县| 繁昌县| 呼玛县| 和顺县| 抚顺市| 高碑店市| 会泽县| 米林县| 寿宁县| 乌兰察布市| 巫山县| 怀安县| 临朐县| 昆山市| 田东县| 保山市| 旬邑县| 静海县| 彩票| 张家港市| 阜新市| 上犹县| 长兴县| 淳安县| 罗山县| 青田县| 彰武县| 册亨县| 新津县| 恩施市| 阿拉善盟| 贵溪市| 定州市| 陆河县| 鄂尔多斯市| 金昌市| 邮箱| 抚松县|