我需要设置验证,用户必须填写/选择页面中的所有详细信息。如果有任何字段为空,想要显示Toast message to fill.
现在我需要RadioButton
在RadioGroup.
我尝试此代码中进行设置验证,但无法正常工作。建议我正确的方法。谢谢。
// 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");
}