Could you please tell me what is the error here? it tells me that “gender” in toast make must be set to final but when I do, the if statements complain that it should not be final
@Override
protected void onCreate(Bundle savedInstanceState) {
String gender = null;
Toast.makeText(this, R.string.ok, Toast.LENGTH_LONG).show();
super.onCreate(savedInstanceState);
setContentView(R.layout.createprofile);
RadioButton rb_male = (RadioButton) findViewById(R.id.maleradiobutton);
String male=rb_male.getText().toString();
RadioButton rb_female = (RadioButton) findViewById(R.id.femaleradiobutton);
String female=rb_male.getText().toString();
if(rb_male.isChecked()) { gender = "male";}
if(rb_female.isChecked()){ gender = "female";}
Button checkgender = (Button) findViewById(R.id.gendercheck);
checkgender.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(ProfileActivity.this, gender.toString(), Toast.LENGTH_LONG);
}
});
}
}
You have too many errors in there to really address completely. They include:
ifstatements checking the male and female buttons must be inside the method onClick(v). If they are outside, then a click does not cause them to be reevaluated and no amount of changing your buttons will change the result you get.genderis already a String,gender.toString()does nothing to change that.Having said all that, here is the code with a lot of those changes made and probably some other stuff cleaned up a bit.
Good luck!
public class AndroidTest extends Activity {
}