I have used recycler view to show data in the list.
In my application, I am running one service after each 10 sec time interval to update data in the list. Now the problem is when I get the data from the service each time list scrolls jumps back to the top position.
I don't know what's wrong with the code.
I have gone through following links but nothing worked out.
Recyclerview Position changing to first position when I Update
Refresh recyclerView adapter with new items on top
notifyDataSetChanged() makes the list refresh and scroll jumps back to the top
Android ListView - scrolls back to top on update
below is the code to initialize recycler view.
mTableOrderAdapter = new
TableOrderAdapter(MainActivity.this,tableOrderModelArrayList);
rvTableOrders.setHasFixedSize(true);
rvTableOrders.setLayoutManager(new
GridLayoutManager(getApplicationContext(), 1));
rvTableOrders.setItemAnimator(new DefaultItemAnimator());
rvTableOrders.setAdapter(mTableOrderAdapter);
when I am getting data from service I just add it into the list and call following method.
runOnUiThread(new Runnable() {
public void run() {
mTableOrderAdapter.notifyDataSetChanged();
}
});
Please help me to get rid of this. Sorry for the English. Thanks in advance.