当前位置: 动力学知识库 > 问答 > 编程问答 >

How to refresh the RecyclerView when taking input from edit text using 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.

Code -:

In Adapter

@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();

}

Set Adapter in RecylerView

 binding.rvFood.setAdapter(null);

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

Getting old list with new one when i enter anything in edit text but when coming from background to foreground correct data shows .

网友答案:

Use adapter to notify the change of data. https://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged()

分享给朋友:
您可能感兴趣的文章:
随机阅读: