Android 单选列表对话框 setSingleChoiceItems

    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

Android 单选列表对话框 setSingleChoiceItems

上一篇:《基于Android平台的大学生课程计划管理系统》论文笔记(六)


下一篇:Android源码分析之Builder模式