Two-Way databinding in EditText

后端 未结 6 858
无人共我
无人共我 2020-12-15 06:20

I have this object

ObservableInt someNumber;

public ObservableInt getSomeNumber()
{
    return someNumber;
}

public void setSomeNumber(ObservableInt numbe         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-15 06:57

    You can do two-way binding on EditText.

    Using one-way data binding, you can set a value on an attribute and set a listener that reacts to a change in that attribute

    variable is string type

    
    

    variable is number

    
    

    `` two back apostrophe do binding automatically

    • convert number to string when setting it on EditText
    • convert string text to number when setting in Model

    Tip

    From documentation you can see, two-way binding can be used for many purpose.

    1. CheckBox, RadioButton, Switch, ToggleButton

    android:checked="@={model.checked}"

    1. RadioGroup - android:checkedButton

    android:checkedButton="@={model.selectedId}"

    1. RatingBar - android:rating

    android:rating="@={model.rating}"

    etc.

提交回复
热议问题