更新时间:2016年11月30日15时45分 来源:传智播客Android培训学院 浏览次数:
1
|
< variable name = "user" type = "cn.itcast.mvvmdemo.User" /> |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
public class User { private String firstname; private String lastname; public User(String firstname, Stringlastname) { this .firstname = firstname; this .lastname = lastname; } public String getFirstname() { return firstname; } public void setFirstname(Stringfirstname) { this .firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(Stringlastname) { this .lastname = lastname; } } |
1
2
3
|
< TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "@{user.firstname}" /> |
01
02
03
04
05
06
07
08
09
10
|
public class MainActivity extends AppCompatActivity { private User user; @Override protected void onCreate(BundlesavedInstanceState) { super .onCreate(savedInstanceState); ActivityMainBinding binding =DataBindingUtil.setContentView( this , R.layout.activity_main); user = new User( "尼古拉斯凯奇" , "赵四" ); binding.setUser(user); } } |