Architecture Components (一)

LiveData https://developer.android.com/topic/libraries/architecture/livedata.html

LiveData 类似 RxJava

具体使用

observer = new Observer>() { @Override public void onChanged(@Nullable List foods) { textView2.setText(foods.get(0).toString()); } }; mModel = ViewModelProviders.of(this).get(FoodModel.class); mModel.getFoods().observe(this, observer);

变化响应

List foods = new ArrayList<>(); foods.add(new Food(1000, "苹果", true, 100, 10, "lixinxin")); mModel.getFoods().setValue(foods);

你可能感兴趣的:(Architecture Components (一))