I'm creating a recyclerview adapter in my onCreate method with an empty list. It is necessary to do so as tagging onto the mAdapter is a scroll listener which allows me to obtain another page from the database server if I scroll up (I have not copied and pasted that code for brevity sake).
public class MainActivity extends ActionBarActivity {
ArrayList<Post> totalPost = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
mAdapter = new MyAdapter(totalPost, mRecyclerView);
mRecyclerView.setAdapter(mAdapter); }
I'm calling my network operation in onResume and onResume happens subsequent to onCreate.
Once I get a success from my network operation, I'm doing this however nothing happens:
totalPost = Lists.newArrayList(result.getPosts()); //saving the network results into an array
mAdapter.notifyDataSetChanged();
I have also tried this:
totalPost = Lists.newArrayList(result.getPosts()); //saving the network results into an array
mAdapter.notifyItemRangeChanged(0, totalPost.size());
I have also tried this and it works but it is not ideal. I create a new adapter here and I also lose my scroll listener. I can also not reference my scroll listener in my method that references my network operations as that would be 'circular reference':
totalPost = Lists.newArrayList(result.getPosts()); //saving the network results into an array
mAdapter = new MyAdapter(totalPost, mRecyclerView);
mRecyclerView.setAdapter(mAdapter);
Why is the adapter not working?
I think your adapter isn't taking in the new values. Try creating a method defined in your adapter class and calling that method with the new values passed in. Like this:
// Adapter Class