single choice AlertDialog – Alertdialog with Radio Button android


learn how to create single choice AlertDialog or AlertDialog with radio Button list in Android.this video show steps involved to create #Alertdialog in #android studio

Hey guys welcome to #Androchunk. In this channel you learn about android tutorials and build android application so make sure you Subscribe.

? Subscribe for more:

✔ Full source code:-

? Overview :

Single Choice AlertDialog consist list of the radio button choices. Use the setSingleChoiceItems() method to create dialog with radiobutton list.

You can customize list but by default it give radiobutton with textview.

An alert dialog can have the following regions

1. Title: A title is optional. Most alerts don’t need titles. If you can summarize a decision in a sentence or two by either
asking a question (such as, “Discard draft?”) or making a statement related to the action buttons (such as, “Click OK to
continue”), don’t bother with a title. Use a title if the situation is high-risk, such as the potential loss of connectivity or
data, and the content area is occupied by a detailed message, a list, or custom layout.

2. Content area: The content area can display a list.

3. Action buttons: You should use no more than three action buttons in a dialog, and most have only two

? Steps to create alertDialog

1.Building the AlertDialog
2.Create AlertDialog Builder
3.Create a list
4.Use setSingleChoiceItems method to builder
5.Setting the button actions for the alert dialog
6.Displaying the dialog
7.Dismiss the dialog

? Building the AlertDialog

Create new dialog fragment file name and extends it to Dialog Fragment.

? Create AlertDialog Builder: The following creates the dialog object ( myAlertBuilder ) to alertdialog.

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

? Create a list: create list of items which display as a radio list.

final String[] list = getActivity().getResources().getStringArray(R.array.choice_items);

? setSingleChoiceItems: Use setSingleChoiceItems method to display a list.

.setSingleChoiceItems(list, position, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {


It take three parameter

1.List: list of the items.
2.Position: default selected radiobutton position
3.Listener: OnClickListener to list.

? Setting the button actions for the alert dialog

Use the setPositiveButton() and setNegativeButton() methods of the AlertDialog.Builder class to set the button actions for the alert dialog.

These methods require a title for the button (supplied by a string resource) and the
DialogInterface.OnClickListener class that defines the action to take when the user presses the button.

You can add only one of each button type to an AlertDialog. For example, you can’t have more than one “positive” button.

Tip: You can also set a “neutral” button with setNeutralButton(). The neutral button appears between the positive and negative buttons.

Use a neutral button, such as “Remind me later”, if you want the user to be able to dismiss the dialog and decide later.

? Displaying the dialog

To display the dialog, call its show() method:;

? Dismiss the dialog

To dismiss the dialog call its dismiss() method: alertDialog.Dismiss();


? Question Of The Day :- Create Alert Dialog with checkbox list

Share your Solution: Facebook:


Share this Question :
? Full source code:-

? Learn more about single Choice Alert Dialog:-

? Subscribe for more Android tutorials:

? If you have a topic you want me to make a video about use #Androchunk in the comments.

If you have any questions, comments or suggestions about this video scripts please leave them in the comments.

? Official documentation:



Music Credits:
Title: Dawn
Artist: Sappheiros


Xem thêm bài viết khác:


Please enter your comment!
Please enter your name here