Skip to content
greenrobot edited this page Aug 29, 2011 · 1 revision

You can bind fields to the values of TextView and its descendants like EditText and Button. Like this you don't even need to touch the View objects directly.

Example: Bind the field value to the view R.id.editText1

 @Value(bindTo=R.id.editText1)
 String value;

Then, you can simply push the value fields into the UI:

    injector.valuesToUi();

And the other way round: from the UI into the value fields:

    injector.uiToValues();

As you saw, you need an Injector object. You will get this by calling one of the static injectInto/inject methods or by calling the constructor directly.

greenInject can also inject into view model classes, not just activities. (Technically, greenInject can inject into any Java objects.)

Example: View Model

    MyViewModel model = new MyViewModel();
    Injector injector = new Injector(activity, model);
    model.buttonText = "PressMe";
    model.editText = "EditMe";
    model.text = "ReadMe";
    injector.valuesToUi();
Clone this wiki locally