码迷,mamicode.com
首页 > 移动开发 > 详细

Android 单选列表对话框 setSingleChoiceItems

时间:2019-11-04 19:36:16      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:add   content   tps   new   nal   layout   undle   order   line   

    private Button button;
    private final CharSequence[] items = { "北京", "上海", "广州" };

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

        button = (Button) findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("请选择以下城市");

                builder.setSingleChoiceItems(items, -1, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        CharSequence sequence = items[which];
                        Toast.makeText(MainActivity.this, "select " + sequence, 1).show();
                    }
                });

                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
    }

技术图片

Android 单选列表对话框 setSingleChoiceItems

标签:add   content   tps   new   nal   layout   undle   order   line   

原文地址:https://www.cnblogs.com/zhangxuechao/p/11793968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!