我需要设置验证,以确保用户必须填写/选择页面中的所有细节。如果有任何字段为空,就要显示Toast message to fill。
现在我需要为RadioGroup
中的RadioButton
设置验证。我尝试了这段代码,但它没有正常工作。请建议正确的方法。谢谢。
// get selected radio button from radioGroup
int selectedId = gender.getCheckedRadioButtonId();
// find the radiobutton by returned id
selectedRadioButton = (RadioButton)findViewById(selectedId);
// do what you want with radioButtonText (save it to database in your case)
radioButtonText = selectedRadioButton.getText().toString();
if(radioButtonText.matches(""))
{
Toast.makeText(getApplicationContext(), "Please select Gender", Toast.LENGTH_SHORT).show();
Log.d("QAOD", "Gender is Null");
}
else
{
Log.d("QAOD", "Gender is Selected");
}