title: How Can I Update data in Recyclerview?
body: <p>I Build an app that load data with <code>Retrofit</code>, into a recyclerview, my recyclerview load perfectly all data from JSON file, but when I try of an update with <code>swipeRefreshLayout</code>, and I intent load again the method <code>loadFirstPage();</code>, but simply add again the same data.</p>
  
  <p>I search in google for any solution, but all my intents do not work in my code.</p>
  
  <p>I intent used <code>adapter.clear</code> and load again, but not work fine.</p>
  
  <p>The idea is if 1 item change from JSON file, update again the data in Recyclerview.</p>
  
  <pre><code>public class historial extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
  
      User user = SharedPrefManager.getInstance(this).getUser();
  
      private static final String TAG = "MainActivity";
  
      PaginationAdapter adapter;
      LinearLayoutManager linearLayoutManager;
      private SwipeRefreshLayout swipeRefreshLayout;
      RecyclerView recyclerView;
      ProgressBar progressBar;
  
      private static final int PAGE_START = 1;
      private boolean isLoading = false;
      private boolean isLastPage = false;
      // limiting to 5 for this tutorial, since total pages in actual API is very large. Feel free to modify.
      private int TOTAL_PAGES = 5;
      private int currentPage = PAGE_START;
  
      private NetworkInterface geosInterface;
      int position;
  
  
  
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.historial);
  
          Toolbar toolbar = findViewById(R.id.toolbar);
          //setting the title
          toolbar.setTitle("elGEos School - Historial");
          //placing toolbar in place of actionbar
          setSupportActionBar(toolbar);
  
          progressBar =  findViewById(R.id.progressBar);
          recyclerView = findViewById(R.id.recycler_view);
  
          adapter = new PaginationAdapter(this);
  
          swipeRefreshLayout = findViewById(R.id.swipe_refresh_layout);
          swipeRefreshLayout.setOnRefreshListener(historial.this);
  
          linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
          recyclerView.setLayoutManager(linearLayoutManager);
          recyclerView.setItemAnimator(new DefaultItemAnimator());
          recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
          recyclerView.setAdapter(adapter);
          recyclerView.addOnScrollListener(new PaginationScrollListener(linearLayoutManager) {
              @Override
              protected void loadMoreItems() {
                  isLoading = true;
                  currentPage += 1;
  
                  // mocking network delay for API call
                  new Handler().postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          loadNextPage();
                      }
                  }, 1000);
              }
  
              @Override
              public int getTotalPageCount() {
                  return TOTAL_PAGES;
              }
  
              @Override
              public boolean isLastPage() {
                  return isLastPage;
              }
  
              @Override
              public boolean isLoading() {
                  return isLoading;
              }
          });
  
          //init serecyclerViewice and load data
          geosInterface = NetworkApi.getClient().create(NetworkInterface.class);
  
          loadFirstPage();
  
  
          swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
  
                  //CODE FOR UPDATE HERE ???
  
                  if (swipeRefreshLayout != null &amp;&amp; swipeRefreshLayout.isRefreshing()) {
                      swipeRefreshLayout.setRefreshing(false);  // This hides the spinner
                  }
              }
          });
  
      }
  
      //TOOL BAR Y MENU
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater menuInflater = getMenuInflater();
          menuInflater.inflate(R.menu.menu3, menu);
          return true;
  
      }
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
  
          switch(item.getItemId()){
              case R.id.aboutback:
  
                  onBackPressed();
  
                  //Toast.makeText(this, "You clicked about", Toast.LENGTH_SHORT).show();
                  break;
  
  
  
          }
          return true;
      }
  
  
  
      private void loadFirstPage() {
          swipeRefreshLayout.setRefreshing(true);
  
          Log.d(TAG, "loadFirstPage: ");
  
          callTopMessage().enqueue(new Callback&lt;TopMessage&gt;() {
              @Override
              public void onResponse(Call&lt;TopMessage&gt; call, Response&lt;TopMessage&gt; response) {
                  // Got data. Send it to adapter
                                  List&lt;Result&gt; results = fetchResults(response);
                  progressBar.setVisibility(View.GONE);
                  adapter.addAll(results);
  
                  if (currentPage &lt;= TOTAL_PAGES) adapter.addLoadingFooter();
                  else isLastPage = true;
                  swipeRefreshLayout.setRefreshing(false);
  
              }
  
              @Override
              public void onFailure(Call&lt;TopMessage&gt; call, Throwable t) {
                  t.printStackTrace();
                  // TODO: 08/11/16 handle failure
                  swipeRefreshLayout.setRefreshing(false);
              }
          });
  
      }
  
      /**
       * @param response extracts List&lt;{@link Result&gt;} from response
       * @return
       */
      private List&lt;Result&gt; fetchResults(Response&lt;TopMessage&gt; response) {
          TopMessage topMessage = response.body();
          return topMessage.getResults();
      }
  
      private void loadNextPage() {
          swipeRefreshLayout.setRefreshing(true);
  
          Log.d(TAG, "loadNextPage: " + currentPage);
  
          callTopMessage().enqueue(new Callback&lt;TopMessage&gt;() {
              @Override
              public void onResponse(Call&lt;TopMessage&gt; call, Response&lt;TopMessage&gt; response) {
                  adapter.removeLoadingFooter();
                  isLoading = false;
  
                  List&lt;Result&gt; results = fetchResults(response);
                  adapter.addAll(results);
  
                  if (currentPage != TOTAL_PAGES) adapter.addLoadingFooter();
                  else isLastPage = true;
                  swipeRefreshLayout.setRefreshing(false);
              }
  
              @Override
              public void onFailure(Call&lt;TopMessage&gt; call, Throwable t) {
                  t.printStackTrace();
                  // TODO: 08/11/16 handle failure
                  swipeRefreshLayout.setRefreshing(false);
              }
          });
      }
  
      private Call&lt;TopMessage&gt; callTopMessage() {
          return geosInterface.getTopMessage(
                  "Comfama",
                  "B",
                  "TTY651",
                  "1",
                  currentPage
          );
      }
  
  
      @Override
      public void onRefresh() {
  
      }
  }
  </code></pre>