RecyclerView scrolls to top

27 views Asked by At

I added a function to my app that the user can refresh the data but the problem that when calling notifyDataSetChanged() it is automatically scrolled to top and i don't want this.

I tried to used DiffUtil and didn't work and tried to make notifyItemChanged() and nothing works

my code in the adapter

public void setData(ArrayList<Student> a) {
        //int previousF = layoutManager.findFirstVisibleItemPosition();
        DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new StudentsDiff(data, a));
        data = new ArrayList<>(a);
        list = new ArrayList<>(a);
        diffResult.dispatchUpdatesTo(this);
        //layoutManager.scrollToPosition(previousF);
    }
0

There are 0 answers