0
我將製作一個收集用戶個人信息的簡單應用程序。但現在我有一些單選按鈕的問題。我想將選定的單選按鈕值添加到SQL。 這是代碼。當點擊所選的單選按鈕時,出現錯誤
MainActivity:
public void add(View view){
EditText fn = (EditText)findViewById(R.id.first_name);
EditText ln = (EditText)findViewById(R.id.last_name);
first_name=fn.getText().toString();
last_name =ln.getText().toString();
radio_group=(RadioGroup)findViewById(R.id.radio_gender);
String gender= ((RadioButton)this.findViewById(radio_group.getCheckedRadioButtonId())).getText().toString();
pf.execSQL("INSERT INTO Persone VALUES('"+first_name+"','"+last_name+"','"+gender+"');");
}
默認情況下是否有任何按鈕被選中?你應該在RadioButton上添加一個onCkeckedChangeListener – joao2fast4u 2014-09-20 19:29:58