0
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 .

Ravi
  • 34,851
  • 21
  • 122
  • 183
Dummy
  • 11
  • 1

1 Answers1

0

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

shanwu
  • 1,493
  • 6
  • 35
  • 45
  • I am setting new adapter every time when list change ,but still its showing same list. Also done binding.executePendingBindings(); – Dummy Nov 29 '16 at 06:06
  • Buddy, you should post your code in the question, not in the comment...@Dummy – shanwu Nov 29 '16 at 07:09
  • sorry i was not aware of this. – Dummy Nov 29 '16 at 07:11
  • Please also show me how you implement EditTextView input function – shanwu Nov 29 '16 at 07:20
  • You also need to add some listener for you edittext, check this question http://stackoverflow.com/questions/2763022/android-how-can-i-validate-edittext-input If you have more questions, let me know – shanwu Nov 29 '16 at 07:26
  • Please select the tick if this answer is helpful to you :D – shanwu Nov 29 '16 at 07:26
  • on edittext calling text watcher android:onTextChanged="@{(s, start, before, count)->foodFragment.onFoodTextChanged(s)}" .In this function api call is there that fetch new list after that setting adapter ... – Dummy Nov 29 '16 at 08:32
  • yeah, you should go a head and try it, if it doesn't work please paste your code in the question @Dummy – shanwu Nov 29 '16 at 11:47