
How to create alert Dialog with checkbox in Android
Sunday, March 17, 2019
3 Comments
In Android Application, There have lots of time you need to show popup option with checkboxes. Most of the time this required for multiple value selection functionalities in your application. In this blog, I will give you the complete process of integrating proper dialogue box in your application with a checkbox. So, Follow the step given below to integrate popup menu.
Step 1: Give below system permissions into AndroidManifest.xml File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> |
Step 2: Create Dialog with below code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dialog dialog; | |
//Dialog Options | |
final String[] items = {"Option 1", "Option 2", "Option 3", "Option 4", "Option 5"}; | |
final ArrayList itemsSelected = new ArrayList(); | |
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this); | |
builder.setTitle("Select Option: "); | |
builder.setMultiChoiceItems(items, null, | |
new DialogInterface.OnMultiChoiceClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int selectedItemId, | |
boolean isSelected) { | |
if (isSelected) { | |
itemsSelected.add(items[selectedItemId]); | |
} else if (itemsSelected.contains(selectedItemId)) { | |
itemsSelected.remove(Integer.valueOf(selectedItemId)); | |
} | |
} | |
}) | |
.setPositiveButton("Done!", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int id) { | |
//Your logic when OK button is clicked | |
} | |
}) | |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int id) { | |
} | |
}); | |
dialog = builder.create(); | |
dialog.show(); |
görüntülüshow
ReplyDeleteücretli show
R3AZ77
https://titandijital.com.tr/
ReplyDeleteçorum parça eşya taşıma
niğde parça eşya taşıma
kastamonu parça eşya taşıma
istanbul parça eşya taşıma
Dİ0
hnjghyjkm
ReplyDeleteشركة تنظيف