0

I'm trying to update the data within the recyclerview every 5 seconds but every time the data is updated the scroll position is not maintained and in automatic it goes up.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_units_impl, container, false);
        initUnitsViewImpl(view);
        return view;
    }

    private void initUnitsViewImpl(View view) {
        initViewID(view);
        initPresenter();
        initOnClickListeners();
    }

private void initPresenter() {
        final UnitsPresenter presenter = new UnitsPresenterImpl(getContext());
        presenter.setView(this);
        presenter.getFullVehicles();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                presenter.getFullVehicles();
                presenter.hideProgressDialog();
                handler.postDelayed(this,5000);

            }
        },5000);

    }

@Override
    public void setUnitList(final List<Unit> unitList) {
        this.vehicles = unitList;
        final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        rvUnits.setLayoutManager(linearLayoutManager);
        unitAdapter = new UnitAdapter(vehicles, getContext());
        rvUnits.setAdapter(unitAdapter);
    }

What am i doing wrong?

Thanks for your help.

Pepelepe
  • 1
  • 1

1 Answers1

0

I'm assuming the issue here is that you're trying to update your recycler view by updating the adapter. You actually do a lot of things element by element, no need to change the adapter.

Check out this answer and let me know if this is what you're looking for.

https://stackoverflow.com/a/48959184/13150066

Lheonair
  • 188
  • 1
  • 10
  • 1
    Thank you for answering, I tried to replace the old list with the new one but still going up after updating. – Pepelepe Jul 17 '20 at 17:35