更新時間:2017-04-14 來源:黑馬程序員Android培訓(xùn)學(xué)院 瀏覽量:
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); } } |