I have small problem in android for Multichoice dialog box.
I have done with this below code for showing a multichoice dialog box and calling that on button click event.
I have set Title, Message, Button and also add Items to the dialog box.
I can see the title, Message and Button that I have set, but I am unable to see the items which I am adding. for that I have googled and almost tried all the code which I found in searching. All approaches not helped me.
Here is my code…
final String[] Values={"Red","Green","Blue"};
final boolean[] selCrayons={true,false,true};
AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle("Crayons List");
dialog.setMessage("Select your favouriate Crayon");
dialog.setMultiChoiceItems(Values,selCrayons,new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
if(arg2) {
Toast.makeText(getApplicationContext(), "Selected Color is " + Values[arg1],Toast.LENGTH_LONG).show();
}
}
});
dialog.setPositiveButton("SAVE",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
AlertDialog alertDialog=dialog.create();
alertDialog.show();
}
setMessageandsetMultiChoiceItemswill not work together. RemovesetMessageand you will be able to see the multi-choice item list.If there is a need to use message and multi-choice list together, you can use your own custom view for the dialog.
For how to set custom view, you can refer AlertDialog.Builder setView (View view) method.