如何在Spinner中使用Set Error?我试过通过类型转换textview但它不会生成错误消息。
submitBt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String patt = "";
boolean b1 = check(name, patt);
if (!b1) {
allergy_nameEt.setError("Enter Disease Name");
return;
}
boolean patt1 = doctor_name.getSelectedItem().toString().equals("Select Doctor");
boolean b2 = check(spin, String.valueOf(patt1));
if (!b2) {
((TextView) doctor_name.getSelectedView()).setError("Please Select Doctor");
return;
} else {
new allergy_category().execute();
}
}
}
答案 0 :(得分:0)
尝试以下列方式实施:
static public void setSpinnerError(Spinner spinner, String errormsg){
View selectedView = spinner.getSelectedView();
if (selectedView != null && selectedView instanceof TextView) {
TextView selectedTextView = (TextView) selectedView;
selectedTextView.setError(errormsg);
}
}
如果你想解雇它,请将error
设为null。