We can add a List and Radio Buttons in Dialog so that user can make choice.
For this we need an array of CharSequences items to use in the list.
AlertDialog levelDialog;
// Strings to Show In Dialog with Radio Buttons
final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Difficulty Level");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch(item)
{
case 0:
// Your code when first option seletced
break;
case 1:
// Your code when 2nd option seletced
break;
case 2:
// Your code when 3rd option seletced
break;
case 3:
// Your code when 4th option seletced
break;
}
levelDialog.dismiss();
}
});
levelDialog = builder.create();
levelDialog.show();
For this we need an array of CharSequences items to use in the list.
AlertDialog levelDialog;
// Strings to Show In Dialog with Radio Buttons
final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
// Creating and Building the Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Difficulty Level");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch(item)
{
case 0:
// Your code when first option seletced
break;
case 1:
// Your code when 2nd option seletced
break;
case 2:
// Your code when 3rd option seletced
break;
case 3:
// Your code when 4th option seletced
break;
}
levelDialog.dismiss();
}
});
levelDialog = builder.create();
levelDialog.show();
No comments:
Post a Comment