Radiobutton in Android

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MyAndroidAppActivity extends Activity {
  private RadioGroup radioSexGroup;
  private RadioButton radioSexButton;
  private Button btnDisplay;
  public void onCreate(Bundle savedInstanceState) {
  public void addListenerOnButton() {
	radioSexGroup = (RadioGroup) findViewById(;
	btnDisplay = (Button) findViewById(;
	btnDisplay.setOnClickListener(new OnClickListener() {
		public void onClick(View v) {
		        // get selected radio button from radioGroup
			int selectedId = radioSexGroup.getCheckedRadioButtonId();
			// find the radiobutton by returned id
		        radioSexButton = (RadioButton) findViewById(selectedId);
				radioSexButton.getText(), Toast.LENGTH_SHORT).show();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s