LiveData https://developer.android.com/topic/libraries/architecture/livedata.html
LiveData 类似 RxJava
具体使用
observer = new Observer<List<Food>>() { @Override public void onChanged(@Nullable List<Food> foods) { textView2.setText(foods.get(0).toString()); } }; mModel = ViewModelProviders.of(this).get(FoodModel.class); mModel.getFoods().observe(this, observer);
变化响应
List<Food> foods = new ArrayList<>(); foods.add(new Food(1000, "苹果", true, 100, 10, "lixinxin")); mModel.getFoods().setValue(foods);