跳至主要内容

博文

目前显示的是标签为“android”的博文

Learn Data Binding of Android

Notice setContentView List like view data binding NavigationView data binding get data from bound view Notice setContentView @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState); MainActivityBinding binding = DataBindingUtil.setContentView( this , R.layout.main_activity); User user = new User( "Test" , "User" ); binding.setUser(user); //setContentView(R.layout.activity_device_info); } Remember to remove the old setContentView() in the onCreate() , or it may override your data binding List-like view data binding This blog and Android guide give us very good example and explanation. What should be noticed is that the example used the RecyclerView to bind data, and I doesn’t find good example with ListView. NavigationView data binding It seems no direct way to make data binding for NavigationView, so I have to implement it in somewhat hacker way: First, in order...