我需要设置验证,用户必须填写/选择页面中的所有细节。如果任何字段是空的想要显示 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");
}