+ Reply to Thread
Results 1 to 2 of 2

Thread: How to set RadioGroup Listener

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    17

    Post How to set RadioGroup Listener

    Let me know how to set radiogroup listener not radiobutton listener.please reply asap.
    Last edited by melina; 08-07-2012 at 12:01 AM.

  2. #2
    Junior Member
    Join Date
    Aug 2012
    Posts
    15
    First Create a RadioGroup in main.xml file
    Code:
    <RadioGroup android:id="@+id/radiogroup"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content">
    <RadioButton android:id="@+id/option1"
          			android:layout_width="fill_parent"
          			android:layout_height="fill_parent"
          			
          			/>
      
    <RadioButton android:id="@+id/option2"
          			android:layout_width="fill_parent"
          			android:layout_height="fill_parent"
          			
          			/>
      </RadioGroup>
    Now Get the reference of radiogroup in activity using

    Code:
    RadioGroup radiogroup=(RadioGroup)findViewById(R.id.radiogroup);
    Set the OnCheckedChangesListener and get the checked radio button id from radiogroup reference




    Code:
    public void onCheckedChanged(RadioGroup group, int checkedId) {
    			RadioButton rb= (RadioButton)findViewById(group.getCheckedRadioButtonId());
    			//rb references to the id of checked radiobutton
    			//getcheckedradiobuttonid returns id ex: r.id.option2
    		}
    	});

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts