injecteer injecteer - 1 year ago 185
Android Question

RecyclerView updates only on scroll

I have a layout with a

with the adapter:

public class SimpleRecyclerAdapter extends RecyclerView.Adapter<SimpleViewHolder> {

protected List<JSONObject> data = new ArrayList<>();

public List<JSONObject> getData() { return data; }

I update it's adapter like:

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 );


The problem is, that I get to see the new item only when I touch or scroll the view.

What am I missing?


to fix the problem I replaced the lines



adapter.notifyItemRangeInserted( loadingMore ? 1 : 0, msgs.length() );

and it worked

Answer Source

try specifying the position of the item inserted or removed instead of notifyDataSetChanged();. you can use

notifyItemInserted(int pos);
notifyItemRangeChanged(int start, int end);`