我需要设置验证的用户必须填写/选择页面中的所有细节。如果有任何字段为空想告诉吐司消息来填补。
在 RadioGroup中。这个我试过code,但没有正常工作。我建议正确的方法。三江源。
//获取选定的单选按钮,从RadioGroup中
INT selectedId = gender.getCheckedRadioButtonId();
//找到单选按钮由归国ID
selectedRadioButton =(单选)findViewById(selectedId);
//你想要做什么用radioButtonText(将它保存到数据库的情况下)
。radioButtonText = selectedRadioButton.getText()的toString();
如果(radioButtonText.matches())
{
Toast.makeText(getApplicationContext(),请选择性别,Toast.LENGTH_SHORT).show();
Log.d(QAOD,性别为空);
}
其他
{
Log.d(QAOD,性别选择);
}
解决方案
如果您想检查只是一个单选
您可以使用器isChecked
功能
如果(radioButton.isChecked())
{
\\检查
}
其他
{
\\未选中
}
如果你有一个 RadioGroup中
您可以使用
如果(radioGroup.getCheckedRadioButtonId()== -1)
{
\\没有单选按钮被选中
}
其他
{
\\的一个单选按钮被选中
}
I need to set validation that user must fill / select all details in a page. If any fields are empty wanna show Toast message to fill.
Now I need set validation for RadioButton
in the RadioGroup.
I tried this code but didn't work properly. Suggest me correct way. Thankyou.
// 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");
}
解决方案
If you want to check on just one RadioButton
you can use the isChecked
function
if(radioButton.isChecked())
{
\\ is checked
}
else
{
\\ not checked
}
and if you have a RadioGroup
you can use
if (radioGroup.getCheckedRadioButtonId() == -1)
{
\\ no radio buttons are checked
}
else
{
\\ one of the radio buttons is checked
}
上一篇:通过使用SOAP API的android Magento的客户登录(验证)客户、API、SOAP、Magento
下一篇:如何可靠是增加的应用程序清单,以确保在Windows XP中,Vista和7提升的权限?应用程序、清单、可靠、权限