-1

i'm making a simple app to practice, the user just inputs name/surname/mail and sex, it saves it in a listview and when you click the list, it opens another activity and shows you the data.

The problem i'm having is that i have the sex option in two radio buttons (male, female) inside a radiogroup (sex) and i don't know how to get the selected radio button text so it shows in the second activity like:
Michael
Smith
michaelsmith@pls.com
Male <- this i can't get.

Any ideas? I've been looking other similar questions but nothing worked for me up to this point. Thanks!!

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • 2
    Possible duplicate of [Android get value of the selected radio button](https://stackoverflow.com/questions/11194515/android-get-value-of-the-selected-radio-button) – Stefan Golubović Mar 17 '18 at 20:10

1 Answers1

1

Make one global variable String mSex;Set onClickLIstener on the RadioGroup as described here

RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup);        
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if(checkedId == R.id.radio_male){
           mSex = "Male";
        } else {
           mSex = "Female";
        }
    }
});

When you start an activity pass data as extra in Intent as described here.

Intent intent = new Intent(this.YourActivity, NextActivity.class);
intent.putExtra("EXTRA_SEX", mSex);
startActivity(intent);

Access that intent on next activity

String sex = getIntent().getStringExtra("EXTRA_SEX");
DimDim
  • 371
  • 1
  • 18