Articles → Android → Multiple choice alert dialog in android

Multiple choice alert dialog in android






Example







Click to Enlarge




Click to Enlarge



public void ButtonClicked(View view) {
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
 final String[] availableTypes = getResources().getStringArray(R.array.sample_array);
 builder.setMultiChoiceItems(R.array.sample_array, null, new DialogInterface.OnMultiChoiceClickListener() {
  @Override
  public void onClick(DialogInterface dialogInterface, int item, boolean isChecked) {
   if (isChecked) {
    Toast.makeText(EditTextDemo.this, availableTypes[item], Toast.LENGTH_LONG).show();
   }
  }
 });
 builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  @Override 
  public void onClick(DialogInterface dialog, int which) {
   dialog.dismiss();
  }
 });
 builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  @Override 
  public void onClick(DialogInterface dialog, int which) {
   Toast.makeText(EditTextDemo.this, "Ok Button Clicked", Toast.LENGTH_LONG).show();
  }
 });
 builder.show();
}



Output





Click to Enlarge




Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, November 24, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250