2

我是安卓新手。所以我无法从警报构建器对话框中的活动中填充无线电组,请帮助我任何人/机构。

4

3 回答 3

4

试试这个:

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();
于 2014-02-14T11:33:32.217 回答
1

您正在尝试做的一些代码会有所帮助。

一般来说,当你在这样的地方创建一个对话框时:

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_layout);

那么您必须使用该对话框来访问其中的布局项,例如:

RadioGroup dialogRadioGroup = (RadioGroup) dialog.findViewById(R.id.myRadioGroup);
于 2014-02-14T11:31:49.640 回答
1
CharSequence[] values = {"Search by Name", "Search by Email", "Search by Mobile"};


    AlertDialog.Builder builder = new AlertDialog.Builder(MainMenu.this);
    builder.setTitle("Select type of Search");

    builder.setSingleChoiceItems(values, -1, new DialogInterface.OnClickListener() {


                @Override
                public void onClick(DialogInterface dialogInterface, int item)
                {
                    switch (item)
                    {
                        case 0:
                            Toast.makeText(MainMenu.this, "First Item :  Search by Name Clicked" , Toast.LENGTH_SHORT).show();
                            break;
                        case 1:
                            Toast.makeText(MainMenu.this, "Second Item :  Search by Email Clicked" , Toast.LENGTH_SHORT).show();
                            break;
                        case 2:
                            Toast.makeText(MainMenu.this, "Third Item :  Search by Mobile Clicked" , Toast.LENGTH_SHORT).show();
                            break;
                    }

                    alertDialogWithRadioButtons.dismiss();

                }
            }
    );

    alertDialogWithRadioButtons = builder.create();
    alertDialogWithRadioButtons.show();
于 2017-12-31T14:25:10.730 回答