forked from liangfeidotme/MasteringAndroidDataBinding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObservableActivity.java
59 lines (45 loc) · 1.76 KB
/
ObservableActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.liangfeizc.databinding.sample.observable;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableArrayMap;
import android.os.Bundle;
import android.view.View;
import com.liangfeizc.databinding.R;
import com.liangfeizc.databinding.sample.BaseActivity;
import com.liangfeizc.databinding.databinding.ActivityObservableBinding;
import com.liangfeizc.databinding.model.ObservableUser;
import com.liangfeizc.databinding.model.PlainUser;
public class ObservableActivity extends BaseActivity {
private ObservableUser user = new ObservableUser();
private PlainUser plainUser = new PlainUser();
private ObservableArrayMap<String, Object> mapUser = new ObservableArrayMap<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityObservableBinding binding = DataBindingUtil.setContentView(
this, R.layout.activity_observable);
setMyName(null);
binding.setUser(user);
binding.setPlainUser(plainUser);
binding.setMapUser(mapUser);
}
public void setOtherName(View view) {
user.setFirstName("zhu");
user.setLastName("chen");
plainUser.firstName.set("zhu");
plainUser.lastName.set("chen");
plainUser.age.set(27);
mapUser.put("firstName", "zhu");
mapUser.put("lastName", "chen");
mapUser.put("age", 27);
}
public void setMyName(View view) {
user.setFirstName("liang");
user.setLastName("fei");
plainUser.firstName.set("liang");
plainUser.lastName.set("fei");
plainUser.age.set(27);
mapUser.put("firstName", "liang");
mapUser.put("lastName", "fei");
mapUser.put("age", 27);
}
}