Dialog对话框

Dialog 对话框
        TODO 对话框  1.进度条对话框(ProgressDialog)  2.确认对话框   3.选择对话框
    TODO 1.进度条对话框(ProgressDialog) 属性 setProgressStyle 显示水平
    TODO                                          setMessage    设定提示信息
    TODO                                            setProgress    设定进度
    TODO                                            dismiss         取消,跳出进度显示界面
    TODO                                              progressDialog. show() 显示
    TODO 2.确认对话框     AlertDialog.Builder builder = new AlertDialog.Builder(this);实例化 ALertDialog
    TODO                     AlertDialog alertDialog = builder.create();创建确认对话框
    TODO                            alertDialog.show();
    TODO                属性      setTitle(设定标题)
    TODO                             setMessage(设定内容)
    TODO            setNegativeButton(左边 长用来设定“取消”)  setNeutralButton(中间)   setPositiveButton(右边 设定“确认”)
   

  TODO 3.选择对话框  builder = new AlertDialog.Builder(this);实例化 ALertDialog

  TODO          属性      setTitle(设定标题)

    TODO                    setSingleChoiceItems(单选)
    TODO                    setMultiChoiceItems(多选)
    TODO                     AlertDialog alertDialog = builder.create();  创建选择对话框
    TODO                             alertDialog.show();

 */
public class Progress_Dialog_Activity extends AppCompatActivity implements View.OnClickListener{

  Button mbutton,confirmbutton,selectbutton,weixinbutton;
     ProgressDialog progressDialog;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress__dialog_layout);

        mbutton = (Button) findViewById(R.id.dialog_progress_btn);
        confirmbutton = (Button) findViewById(R.id.dialog_confirm_btn);
        selectbutton = (Button) findViewById(R.id.dialog_select_btn);
        weixinbutton = (Button) findViewById(R.id.dialog_weixin_btn);

        mbutton.setOnClickListener(this);
        confirmbutton.setOnClickListener(this);
        selectbutton.setOnClickListener(this);

        weixinbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Dialog weixinDialog = new WxD(Progress_Dialog_Activity.this);    //todo WxD 类的实例
                weixinDialog.show();
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.dialog_progress_btn:
                progressDialog = new ProgressDialog(this);     //获得实例
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//显示水平
                progressDialog.setMessage("进度显示");
                progressDialog.show();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for(int i=0;i<=100;i++){
                            progressDialog.setProgress(i);
                            SystemClock.sleep(200);//todo 系统自带的休眠器
                        }
                        progressDialog.dismiss();// todo 取消,跳出进度显示界面
                    }
                }).start();
                break;
            case R.id.dialog_confirm_btn:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("RemindYou");
                builder.setMessage("Will you continue?");
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(Progress_Dialog_Activity.this,"Cancel",Toast.LENGTH_SHORT).show();
                    }
                });
                builder.setNeutralButton("Continue", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(Progress_Dialog_Activity.this,"Continue",Toast.LENGTH_SHORT).show();
                    }
                });
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(Progress_Dialog_Activity.this,"Yes",Toast.LENGTH_SHORT).show();
                    }
                });
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
                break;
            case R.id.dialog_select_btn:
                    builder = new AlertDialog.Builder(this);
                    builder.setTitle("Interesting ");
                    String[] single = {"reading","writing","painting"};
                    builder.setSingleChoiceItems(single, 0, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(Progress_Dialog_Activity.this,"你选择是 "+i,Toast.LENGTH_SHORT).show();
                        }
                    });
                AlertDialog alertDialog2 = builder.create();
                alertDialog2.show();
        }

    }

}

微信类的代码

public class WxD  extends AlertDialog {
    private Activity mContext;
    public WxD(Activity context) {
        super(context);
        mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wei_xin_layout);

        Button confirm = (Button) findViewById(R.id.exitBtn0);
        Button cancel = (Button) findViewById(R.id.exitBtn1);

        confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mContext.finish();//todo 结束当前activity
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();//todo 结束提示界面
            }
        });
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值