更新时间:2017-04-14 来源:黑马程序员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); } } |