【发布时间】:2017-03-26 09:01:38
【问题描述】:
我必须对两个单选按钮作为字符串使用什么方法(例如:性别)。字符串——错误“此处不允许字符串声明”我正在尝试从网站向此代码添加单选按钮:Learn2crack
if(radioButton1.isSeleceted())
String temp = radioButton1.getText().toString();
if(radioButton2.isSeleceted())
String temp = radioButton2.getText().toString();
来源: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
我的xml代码:
<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>
PHP MySql 的 java 代码中的字符串声明
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
}
【问题讨论】:
-
isSeleceted是一个错字。这是isSelected。你的es 太多了。无论如何,您可能不想要这种方法。你想要isChecked()。 -
是的
isChecked()已解决,但string declaration not allowed错误未解决。 @MikeM。 -
您的问题可能已经解决了。签出这个enter link description here
-
数据库在哪里?您是否将数据存储在 Android 设备上的 SQLite 数据库中?还是您将数据存储在 Internet 上某个服务器上的数据库中?
-
我正在使用 PHP MySQL 数据库(Xampp 服务器)@Code-Apprentice