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






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


Miscellaneous
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





14 comments:

  1. This comment has been removed by the author.

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

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

    ReplyDelete
    Replies
    1. It should be levelDialog.dismiss();

      Delete
    2. dialog.dismiss(); works for me

      Delete
  4. how to save the state of those radio buttons

    ReplyDelete
  5. Thanks. it's useful example.

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

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

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

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

    ReplyDelete