常用选择对话框

 

package com.lanxiang.myapps;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


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

    private void initView() {

    }

    private void initData() {

    }

    public void click1(View v) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("提示");
        builder.setMessage("是否删除当前选择项?");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this, "啊啊啊啊啊啊啊啊啊啊", Toast.LENGTH_SHORT).show();
            }
        });
        builder.setNegativeButton("取消", null);
        builder.show();
    }

    public void click2(View v) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("请选泽你想免费的商品");
        final String[] items = {"别墅房","美女主播","黄瓜"};
        /**
         * 单选对话框
         */
        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this, "我就知道你会选我的!", Toast.LENGTH_SHORT).show();
                dialogInterface.dismiss();
            }
        });
        //设置用户不可点击除对话框以外的地方,导致对话框消失
        builder.setCancelable(false);
        builder.setNegativeButton("取消",null);
        builder.show();
    }
    public void click3(View view){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("请选择你喜欢的美女类型");
        String[] items = {"少女","少妇","成熟","小鸟依人","霸道总裁","活泼性感"};
        boolean[] checkedItems = {true, true, false, false,false,false};
        builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                Toast.makeText(MainActivity.this, "我就知道你会选我的!", Toast.LENGTH_SHORT).show();

            }
        });
        builder.setNegativeButton("取消选择", null);
        builder.show();
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值