如何使用数据绑定从编辑文本中获取输入时刷新RecyclerView

时间:2016-11-29 05:57:44

标签: android-recyclerview android-databinding

First time data loaded correct in recyclerview using databinding ,Need to update the recylerview when user type anything in editText , onTextchange getting new list that need to show in recylerview but its showing old list only.
How to implement this using Databing.

代码 - :     在适配器

@Override
public void onBindViewHolder(FoodsAdapter.ViewHolder holder,final int position) {
        binding=holder.getBinding();
        binding.setAdapter(this);
        binding.setActivity(mActivity);
        binding.setVariable(BR.food,foodList.get(position));
     /*   binding.setFood(foodList.get(position));*/
        binding.setPosition(position);
        binding.executePendingBindings();
}

在RecylerView中设置适配器

 binding.rvFood.setAdapter(null);                                  
 binding.rvFood.setAdapter(new FoodsAdapter(activity,foodList));

当我在编辑文本中输入任何内容但从背景到前景的正确数据显示时,使用新列表获取旧列表。

1 个答案:

答案 0 :(得分:0)