我对编程非常陌生。我想要做的是,当有人没有写任何东西时,使用“请写下你的答案”这样的setError()。但是,当有人单击文本框时,我希望文字消失,但错误符号保留。我已经看过并尝试过这样的解决方案,你可以通过重写setError来设置图片。
public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setError(CharSequence error, Drawable icon) {
setCompoundDrawables(null, null, icon, null);
}但是,使用此方法时,我无法设置charsequence
发布于 2016-11-02 10:55:16
你可以在点击按钮的时候设置错误,比如说注册或者登录,不管你的功能是什么。并检查字符串是否为空,然后将错误设置为
String str = myEditText.getText().toString();
if (str.length() == 0 || str.equals("")) {
myEditText.setError("field can't be empty");
} 发布于 2016-11-02 11:32:43
简单的按钮点击处理,并显示错误消息,如下所示。这是我的工作。
@Override
public void onClick(View v) {
String data = mEditText.getText().toString();
if(data.isEmpty())
{
mEditText.setError(""Please write your your answer.");
return;
}
}https://stackoverflow.com/questions/40371580
复制相似问题