public class MainActivityModel { private int catCount; public MainActivityModel(CatRecordFromDb cats) { // init your viewmodel here // ... } @BindModel({ R.id.practice_image, R.id.buttonStart }) // RO binding to imageUri for ImgView and ImgButton public String getFancyImage() { return getModel().imageUrl; } @BindModel(R.id.editNumberOfCats) // getter for EditText value initialisation public int getCatsCount() { // method name can be anything, getters just need the "get" in front return catCount; // conversion from int to String happens magically at google offices* (even offline!) } @BindModel(R.id.editNumberOfCats) // setter to update the model from the control public void setCatNumber(int catCount) { // setter name doesn't need to match getter's, just be "set<Whatever>" this.catCount = catCount; // the value is already converted into target type recalculateTotal(); // do the magic after cat count changed } } // * Measurement of correctness of this description is pending indifinitely
binder = doo.bandera.Models.Bind(this, new MainActivityModel(catsFromDb)); // doo.bandera.Models.Bind for your activity/model pair is generated during compilation
binder.updateDirtyValues(); // scans what changed in the model and updates widgets
Source: https://habr.com/ru/post/190072/
All Articles