I have an app which stores weather information in an SQLite database and displays it in a RecyclerView. I am trying to implement a function to update the database and refresh the RecyclerView with the updated contents in the table.

I have implemented this to happen when the users click the "refresh" button. However, the RecyclerView only updates on the second click of the button, I cannot figure out why it isn't updating on the first click.

The below class is an Async task which gets weather data from an API and parses it successfully. The "onPostExecute" statement is where I update the database values.

```
    public class UpdateWeather extends AsyncTask<String, Void, CurrentWeather> {

    @Override
    protected CurrentWeather doInBackground(String... strings) {
        //CONNECTION CLASS
        //connect to API and download JSON data
        String data = ((new HTTPClient()).getForecastData(strings[0]));
        currentWeather = CurrentWeatherParser.getCurrentWeather(data); //Use the Parser class to get relevant data from the JSON

        return currentWeather;
    }

    @Override
    protected void onPostExecute(CurrentWeather currentWeather) {
        super.onPostExecute(currentWeather);
        ContentValues cv = new ContentValues();
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_0, currentWeather.currentCondtion.getCityName());
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_1, "countrycodetest");
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_7, "test3");
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_5, "sunrisetest");
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_6, currentWeather.currentCondtion.getSunset());
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_8, "test4");
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_2, "test2");
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_3, 2.33);
        cv.put(CurrentWeatherContract.CurrentWeatherEntry.COL_4, 23.3);

        //update table
        myDB.update(CurrentWeatherContract.CurrentWeatherEntry.TABLE_NAME, cv, "City_Name = ?",new  String[] {currentWeather.currentCondtion.getCityName()});

    }
}

//execute the async task based on a city name.
public void updateCurrentWeather(String city) {
    FavouritesActivity.UpdateWeather updateWeather = new FavouritesActivity.UpdateWeather();
    updateWeather.execute(Utilities.BASEURL_CR + city + Utilities.APIKEY);
}

```

My on click listener:

```
    refresh.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    updateCurrentWeather("Madrid");
                    recyclerView.setLayoutManager(new LinearLayoutManager(FavouritesActivity.this));
                    mAdapter = new CurrentWeatherAdapter(FavouritesActivity.this, getAllItems());
                    recyclerView.setAdapter(mAdapter);
                    getAllItems();

                }
            }
    );

```

GetAllItems() method:

```
    private Cursor getAllItems()
{
    return myDB.query(
            CurrentWeatherContract.CurrentWeatherEntry.TABLE_NAME,
            null,
            null,
            null,
            null,
            null,
            CurrentWeatherContract.CurrentWeatherEntry._ID + " DESC"
    );
}

```