Thursday, January 3, 2013

Adding Radio Buttons In Alert Dialog

The Android Development Tutorials blog contains Basic as well as Advanced android tutorials.Go to Android Development Tutorials to get list of all Android Tutorials.

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.

Some More Good  Android Topics
Android Custom Alert Dialog Example
 Customize Radio Button In Android 
Customizing Toast In Android 
 Showing Toast for Longer Time
Customizing Checkboxes In Android  
Customizing Progress Bar
To learn Basic of Android Animation  go to  Android Animation Basics

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) {
                        case 0:
                                // Your code when first option seletced
                        case 1:
                                // Your code when 2nd  option seletced
                        case 2:
                               // Your code when 3rd option seletced
                        case 3:
                                 // Your code when 4th  option seletced           
                levelDialog = builder.create();

More Android Topics:


New Advance Topics:
Android ImageSwitcher                    Android TextSwitcher                                Android ViewFlipper
Android Gesture Detector               Handling/Detecting Swap Events                Gradient Drawable
Detecting Missed Calls                    Hide Title Bar                                           GridView Animation

 Beginning With Android
      Android : Introduction                                                              Configuring Eclipse for Android Development
     Creating Your First Android Project                                           Understanding Android Manifest File of your android app

 Advance Android Topics                                                              Customizing Android Views

Working With Layouts                                                                Working With Views

Understanding Layouts in Android                                                   Using Buttons and EditText in Android
Working with Linear Layout (With Example)                                     Using CheckBoxes in Android
Nested Linear Layout (With Example)                                              Using AutoCompleteTextView in Android                                                                                          Grid View
Relative Layout In Android                                                               ListView
Table Layout                                                                                   Android ProgressBar
Frame Layout(With Example)                                                          Customizing ProgressBar
Absolute Layout                                                                             Customizing Radio Buttons
Grid Layout                                                                                    Customizing Checkboxes In Android

Android Components                                                                 Dialogs In Android

Activity In Android                                                                    Working With Alert Dialog
Activity Life Cycle                                                                    Adding Radio Buttons In Dialog
Starting Activity For Result                                                       Adding Check Boxes In Dialog
Sending Data from One Activity to Other in Android                    Creating Customized Dialogs in Android
Returning Result from Activity                                                   Creating Dialog To Collect User Input
Android : Service                                                                     DatePicker and TimePickerDialog
BroadcastReceiver                                                                   Using TimePickerDialog and DatePickerDialog In android

Menus In Android                                                                ListView:
Creating Option Menu                                                               Populating ListView With DataBase
Creating Context Menu In Android                                              Populating ListView with ArrayList
                                                                                               ListView with Custom Adapter

Toast                                                                                      Working With SMS
Customizing Toast In Android                                                       How to Send SMS in Android
Customizing the Display Time of Toast                                        How To Receive SMS
Customizing Toast At Runtime                                                  Accessing Inbox In Android
Adding Image in Toast
Showing Toast for Longer Time

TelephonyManager                                                            Storage: Storing Data In Android
Using Telephony Manager In Android                                          SharedPreferences In Android
                                                                                              Reading and Writing files to Internal Stoarage
Working With Incoming Calls                                             DataBase
How To Handle Incoming Calls in Android                                Working With Database in Android
How to Forward an Incoming Call In Android                            Creating Table In Android
CALL States In Android                                                          Inserting, Deleting and Updating Records In Table in Android

Notifications In Android
How To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog


  1. This comment has been removed by the author.

  2. Replies
    1. mine is not working can u provide the whole code thanks....

  3. Should be "dialog.dismiss();" instead of "levelDialog.dismiss();" at the end of the onClickListener

  4. how to save the state of those radio buttons

  5. Thanks. it's useful example.

  6. Error:(128, 33) error: variable levelDialog might not have been initialized

  7. How to set selected for radio button in alert dialog?

  8. How can I change the color of the circules???

  9. how can I change the color of the circle of the radio button???

  10. Cannot resolve symbol 'levelDialog'???

  11. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. Android gaming

  12. Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily motorola two way radios

  13. Before we explore the different radio and service options available, let's first consider some basics that apply to two-way radios and radio services. First, more power means greater distances.

  14. Have you ever been hiking or camping with your family and you and your kids become separated from each other? This is not the time to discover that your cell phone does not have a signal. walky talky

  15. I respect this article for the all around scrutinized content and superb wording. I got so included in this material that I couldn't quit perusing. I am inspired with your work and expertise. Much thanks to you to such an extent. running snail radio

  16. Cool stuff you have got and you keep update all of us. history radio

  17. I can read all the opinions of others as well as i gained information to each and everyone here on your site. Just keep on going dude. Check over here: 경마

  18. Searching for a great site. I was so impressed to yours. This will probably give me ideas for my work. Thank you 사설토토