What method I have to use for two radio buttons as strings(eg: gender). String --the error "string declaration is not allowed here" I'm trying to add radio button to this code from website:Learn2crack
if(radioButton1.isSeleceted())
String temp = radioButton1.getText().toString();
if(radioButton2.isSeleceted())
String temp = radioButton2.getText().toString();
Source: Source of this if condition code
btn_register.setOnClickListener(this);
tv_login.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.tv_login:
goToLogin();
break;
case R.id.btn_register:
String name = et_name.getText().toString();
String email = et_email.getText().toString();
String password = et_password.getText().toString();
String aadhar = et_aadhar.getText().toString();
String phone = et_phone.getText().toString();
String address = et_address.getText().toString();
String gender = radioM.getText().toString();// i stucked here
My xml code:
<RadioGroup
android:id="@+id/radioGrp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<RadioButton
android:id="@+id/radioM"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:checked="false"
android:layout_weight="1"
android:textSize="14dp"
android:text="Male"
/>
<RadioButton
android:id="@+id/radioF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:checked="false"
android:layout_weight="1"
android:textSize="14dp"
android:text="Female"
/>
</RadioGroup>
String declaration in java code for PHP MySql
private String gender;
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;// in my database text( eg: M/F) store in gender field
}