Android 多选列表对话框 setMultiChoiceItems

    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 OnClickListener() {

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

                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

                builder.setTitle("请选择以下城市");

                builder.setMultiChoiceItems(items, new boolean[] { false, false, false },
                        new OnMultiChoiceClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                // TODO Auto-generated method stub

                            }
                        });

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

image

posted @ 2019-11-04 19:09  thomas_blog  阅读(2208)  评论(0编辑  收藏  举报