我是Android新手。所以我不能从Alert Builder对话框中的活动填充无线组,请帮助我任何一个/实体。

最佳答案

试试这个:

AlertDialog.Builder builderSingle = new AlertDialog.Builder(MyActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("MyDialog");

final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
        MyActivity.this,
        android.R.layout.select_dialog_singlechoice);

for (int i = 0; i < 10; i++) {
    arrayAdapter.add("Item " + i);
}
// cancel button
builderSingle.setNegativeButton("cancel",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

builderSingle.setAdapter(arrayAdapter,
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Log.i("Selected Item : ", arrayAdapter.getItem(which));
                dialog.dismiss();

            }
        });
builderSingle.show();

关于android - 如何在 Activity 中的“警报生成器”对话框中填充单选组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21778151/

10-09 16:04