I have a layout with RecyclerView with an adapter:
public class SimpleRecyclerAdapter extends RecyclerView.Adapter<SimpleViewHolder> { protected List<JSONObject> data = new ArrayList<>(); public List<JSONObject> getData() { return data; } }
I am updating it as:
public void udpdateFromJson( JSONObject payload ) { JSONArray msgs = payload.optJSONArray( "messages" ); for( int ix = 0; null != msgs && ix < msgs.length(); ix++ ){ JSONObject o = msgs.optJSONObject( ix ); if( loadingMore ) adapter.getData().add( 1 + ix, o ); else adapter.getData().add( o ); } adapter.notifyDataSetChanged(); recyclerView.invalidate(); }
The problem is that I only see a new element when I touch or scroll the view.
What am I missing?
UPDATE:
to fix the problem, I replaced the lines
adapter.notifyDataSetChanged(); recyclerView.invalidate();
from
adapter.notifyItemRangeInserted( loadingMore ? 1 : 0, msgs.length() );
and he worked
android android-recyclerview recycler-adapter
injecteer
source share