【发布时间】:2015-01-17 18:09:52
【问题描述】:
让我们看一个来自here 的简单示例: 这是一个带有 textview 绑定的简单布局文件:
<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 等,它怎么知道要绑定什么?
【问题讨论】:
标签: android mvvm robobinding