对于我的微调器,我有一个隐藏文本和验证码,如果跳过微调器,则显示错误信息。虽然代码在未选择微调器的情况下有效,但即使我在微调器中选择了一个选项,错误信息也会一直显示。
final int pos = spinner5.getSelectedItemPosition();
boolean failflag = false;
String name = null;
if (pos!=0) {
} else {
failflag = true;
TextView errorText = (TextView)spinner6.getSelectedView();
errorText.setError("");
errorText.setTextColor(Color.RED);
errorText.setText("Enter your Marital Status");
}
答案 0 :(得分:0)
您需要在设置错误之前设置条件。
像(下面的伪代码):
If (textview.text = invalid) {
textview.setError(Please put valid text)
} else {
textview.setError(null)
}
答案 1 :(得分:0)
您应该在微调器中设置OnItemSelectedListener
,以便在选择值后隐藏错误:
spinner5.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != 0) {
TextView errorText = (TextView)spinner6.getSelectedView();
errorText.setText("");
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
答案 2 :(得分:0)
试试这个......
spinner6.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView errorText = (TextView)spinner6.getSelectedView();
if (position > 0) {
errorText.setText("");
}else{
failflag = true;
errorText.setError("");
errorText.setTextColor(Color.RED);
errorText.setText("Enter your Marital Status");
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});