我是Android開發的新手。我使用Robobinding (MVVM framework)來開發Android應用程序,但我沒有找到任何解決方案來在演示模型中創建驗證(而不是在活動中)。有沒有人遇到類似的問題?選擇哪種方法? 我需要財產以後這樣的:Robobinding框架驗證(Android)
public class LoginPM extends AbstractPresentationModel {
private String login;
public String getLogin() { return login; }
public void setLogin(String value)
{
if (!StringComparator.IsEquals(this.login, value))
{
if(TextUtils.isEmpty(value))
{
setError("login", "Field cannot be left blank.");
return;
}
this.login = value;
firePropertyChange("login");
}
}
}
*此外,您還可以實現錯誤相應的TextView和更新錯誤信息綁定屬性。*這真的可能嗎?我認爲TextView和EditText沒有可訪問的錯誤屬性。只有方法setError(「MSG」)是可能的。 – Hollerweger 2014-11-06 10:23:08
@霍拉,這當然是可能的。您只需爲任何其他綁定屬性實現TextView.error的綁定屬性即可。看看文檔和源代碼,如果你有興趣。這很容易做到。 – Cheng 2014-11-07 11:29:52
好吧,我會嘗試,我認爲它不可訪問,因爲它不在XML屬性列表中:http://developer.android.com/reference/android/widget/TextView.html – Hollerweger 2014-11-07 15:15:21