1
让我们检查来自here一个简单的例子: 这里是一个TextView一个简单的布局文件绑定:RoboBinding如何视图模型知道变量返回
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://robobinding.org/android">
<TextView
bind:text="{hello}" />
...
<Button
android:text="Say Hello"
bind:onClick="sayHello"/>
,这里是这个视图模型布局:
@org.robobinding.annotation.PresentationModel
public class PresentationModel implements HasPresentationModelChangeSupport {
private String name;//how does framework now what to set name to ?
public String getHello() {
return name + ": hello Android MVVM(Presentation Model)!";
}
...
public void sayHello() {
firePropertyChange("hello");
}
}
我的问题是viewModel如何知道什么名字?它没有被设置在任何地方?如果我有很多变量,比如name2,name3等,会怎样知道要绑定什么?