Showing posts with label Radio Button. Show all posts
Showing posts with label Radio Button. Show all posts

Wednesday, June 5, 2013

Customizing Radio Button In Android

Custom Radio Buttons

In android we can customize  the default Radio Buttons. Default Radio Buttons are small and also not attractive, By using customized Radio Buttons we can design more attractive and better user interface.

To customize Radio Buttons we need to have two drawables
1:  when radio button is selected.
2:  when radio button is not selected.

In this example I have  used these two drawables for selected and not selected state.




                                          



We need to define the xml for our customized Radio Buttons

create the custom_radio_button.xml  file and put it in drawable folder( if drawable folder is not there ,cerate it (inside res folder, and put custom_checkbox_design.xm  file in this folder). It should look like following in pacakgae explorer

res
  -> drawable
         -> custom_radio_button.xml


custom_radio_button.xml

<?xml version="1.0" encoding="utf-8"?>
    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
         <item android:state_checked="true" android:drawable="@drawable/checkedradiobutton" />
         <item android:state_checked="false" android:drawable="@drawable/unchekedradiobutton" />
    
    </selector>
    
    

In RadioButton(in your .xml file)   set android:button  property to the  custom_checkbox_design.xml   drawable  like

android:button="@drawable/custom_checkbox_design"

See the differences in default checkbox and customize checkbox in below screenshot




<LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:orientation="vertical"
               xmlns:android="http://schemas.android.com/apk/res/android">

   <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                android:gravity="center_horizontal"
                android:textSize="25dp"
                android:text="Default Radio Buttons" />
 

  
 
   <!--   Default RadioButtons  -->

   <RadioButton
                   android:id="@+id/radioButtonDeafult1"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_gravity="center_horizontal"
                   android:text="Radio Button Selected"
                   android:layout_marginTop="20dp"
                   android:checked="true"
                   android:textSize="20dp" />
     <RadioButton
                   android:id="@+id/radioButtonDeafult2"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:text="Radio Button Not Selected"
                   android:layout_marginTop="10dp"
                   android:checked="false"
                   android:textSize="20dp" />
   
   
        <View
                   android:layout_width="fill_parent"
                   android:layout_height="1dp"
                   android:layout_marginTop="20dp"
                   android:background="#B8B894" />
   
      <TextView
                   android:id="@+id/textView1"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginTop="30dp"
                   android:gravity="center_horizontal"
                   android:textSize="25dp"
                   android:text="Customized Radio Buttons" />
    
    
      <!--   Customized RadioButtons  -->

   <RadioButton
                   android:id="@+id/radioButtonCustomized1"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:text="   Radio Button Selected"
                   android:layout_marginTop="20dp"
                   android:checked="true"
                   android:button="@drawable/custom_radio_button"
                   android:textSize="20dp" />
     <RadioButton
                   android:id="@+id/radioButtonCustomized2"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:text="  Radio Button Not Selected"
                   android:layout_marginTop="10dp"
                   android:checked="false"
                   android:button="@drawable/custom_radio_button"
                   android:textSize="20dp" />
 

</LinearLayout>

Friday, May 31, 2013

Dialog With Radio Button

Android Tutorials for Beginners


We can add a List and Radio Buttons in Dialog so that user can make choice.

For this we need an array if CharSequences items to use in the list.


Some More Good  Android Topics
Customizing Toast In Android 
 Showing Toast for Longer Time
Customizing Checkboxes In Android  
Customizing Progress Bar





AlertDialog levelDialog;


final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
               
                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) {
                  
                    Intent i=new Intent(getApplicationContext(),SudokuActivity.class);;
                    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:



 

Advance Android Topics


                   Customizing Toast In Android 
                   Showing Toast for Longer Time
                   Customizing the Display Time of Toast
                   Using TimePickerDialog and DatePickerDialog In android
                   Animating A Button In Android
                    Populating ListView With DataBase

                    Customizing Checkboxes In Android 
                    Increasin Size of Checkboxes
                    Android ProgressBar
                    Designing For Different Screen Sizes
                    Handling Keyboard Events

  

Android : Introduction


       Eclipse Setup for Android Development

                     Configuring Eclipse for Android Development

          Begging With Android

                     Creating Your First Android Project
                     Understanding Android Manifest File of your android app


         Working With Layouts

                      Understanding Layouts in Android
                          Working with Linear Layout (With Example)
                                Nested Linear Layout (With Example)
                          Table Layout
                          Frame Layout(With Example)
                         Absolute Layout
                         Grid Layout


       Activity

                     Activity In Android
                     Activity Life Cycle
                     Starting Activity For Result
                     Sending Data from One Activity to Other in Android
                     Returning Result from Activity

     Working With Views

                     Using Buttons and EditText in Android 
                     Using CheckBoxes in Android 
                     Using AutoCompleteTextView in Android
                     Grid View

       Toast

                     Customizing Toast In Android
                     Customizing the Display Time of Toast
                     Customizing Toast At Runtime
                     Adding Image in Toast
                     Showing Toast for Longer Time

     Dialogs In Android

                     Working With Alert Dialog
                     Adding Radio Buttons In Dialog
                     Adding Check Boxes In Dialog
                     Creating Customized Dialogs in Android
                    Adding EditText in Dialog

                   Creating Dialog To Collect User Input

                 DatePicker and TimePickerDialog

                              Using TimePickerDialog and DatePickerDialog In android

    Working With SMS

                  How to Send SMS in Android
                  How To Receive SMS
                  Accessing Inbox In Android

    ListView:

               Populating ListView With DataBase

      Menus In Android

                    Creating Option Menu
                    Creating Context Menu In Android

      TelephonyManager

                    Using Telephony Manager In Android

     Working With Incoming Calls

                    How To Handle Incoming Calls in Android
                    How to Forward an Incoming Call In Android
                   CALL States 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

   Storage:  Storing Data In Android


               Shared Prefferences  In Android

                             SharedPreferences In Android

               Files: File Handling In Android

                              Reading and Writing files to Internal Stoarage
                              Reading and Writing files to SD Card 
                           

                DataBase : Working With Database

                             Working With Database in Android
                             Creating Table In Android
                             Inserting, Deleting and Updating Records In Table in Android
                             How to Create DataBase in Android
                             Accessing Inbox In Android

     Animation In Android:

                  Animating A Button In Android