title: Why is my database list not showing at first and only showing after a click?
body: <p>I used Room Architecture for a simple database to display a list of city names.
  The database is working but my only issue is that the database list only shows after I tap on the Edit text field. I have attached the respective code and some screenshots for better understanding.
  I am sure it is some minor logical error that I've done. Can anyone help?
  Thanks in advance.</p>
  <p><strong>Locations Activity</strong></p>
  <pre><code>package com.example.smweather;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.lifecycle.Observer;
  import androidx.lifecycle.ViewModelProvider;
  import androidx.recyclerview.widget.ItemTouchHelper;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  import retrofit2.Call;
  import retrofit2.Callback;
  import retrofit2.Response;
  import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ArrayAdapter;
  import android.widget.AutoCompleteTextView;
  import android.widget.Toast;
  
  import java.util.List;
  
  public class LocationsActivity extends AppCompatActivity {
  
      private LocationViewModel locationViewModel;
  
      AutoCompleteTextView trialedCity;
      String[] trialCityNames;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_locations);
  
          setTitle(&quot;Locations&quot;);
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          trialedCity = findViewById(R.id.aedCity);
          trialCityNames = getResources().getStringArray(R.array.sample_city_names);
          ArrayAdapter&lt;String&gt; sampleCityListAdapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_1, trialCityNames);
          trialedCity.setAdapter(sampleCityListAdapter);
  
          trialedCity.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  trialedCity.setCursorVisible(true);
              }
          });
  
          RecyclerView locationRecyclerView = findViewById(R.id.location_recycler_view);
          locationRecyclerView.setLayoutManager(new LinearLayoutManager(this));
          locationRecyclerView.setHasFixedSize(true);
  
          final LocationAdapter adapter = new LocationAdapter();
          locationRecyclerView.setAdapter(adapter);
  
          locationViewModel = new ViewModelProvider(this, 
          ViewModelProvider.AndroidViewModelFactory.getInstance(this.getApplication()))
                  .get(LocationViewModel.class);
          locationViewModel.getAllLocations().observe(this, new Observer&lt;List&lt;Location&gt;&gt;() {
              @Override
              public void onChanged(List&lt;Location&gt; locations) {
                  adapter.submitList(locations);
              }
          });
  
          adapter.setOnLocationClickListener(new LocationAdapter.OnLocationClickListener(){
              @Override
              public void onLocationClick(Location location) {
  
                  String trialvalue = location.getStrlocation();
                  Intent resultIntent = new Intent();
                  resultIntent.putExtra(&quot;trialValue&quot;,trialvalue);
                  setResult(RESULT_OK,resultIntent);
                  finish();
              }
          });
  
          // TODO: 12-08-2020 swipe gesture to delete
          new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT) {
              @Override
              public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull                         
                   RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
                  return false;
              }
  
              @Override
              public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
                  locationViewModel.delete(adapter.getLocationAt(viewHolder.getAdapterPosition()));
                  Toast.makeText(LocationsActivity.this, &quot;Location deleted&quot;, 
                     Toast.LENGTH_SHORT).show();
              }
          }).attachToRecyclerView(locationRecyclerView);
  
      }
  
      public void trialdata(View view) {
          Retrofit retrofit = new Retrofit.Builder()
                  .baseUrl(myApi.BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
  
          myApi trialapi = retrofit.create(myApi.class);
  
          Call&lt;Example&gt; exampleCall = 
          trialapi.getinfo(trialedCity.getText().toString().trim(),MainActivity.openWeatherapiKey);
          exampleCall.enqueue(new Callback&lt;Example&gt;() {
              @Override
              public void onResponse(Call&lt;Example&gt; call, Response&lt;Example&gt; response) {
                  if (response.code() == 404) {
                      Toast.makeText(LocationsActivity.this, &quot;Invalid City&quot;, 
                    Toast.LENGTH_SHORT).show();
                  } else if (response.code() == 429) {
                      Toast.makeText(LocationsActivity.this, &quot;Your account is temporary blocked due to 
                    exceeding of requests limitation of your subscription type.&quot;, 
                Toast.LENGTH_SHORT).show();
                  } else if (!response.isSuccessful()) {
                      Toast.makeText(LocationsActivity.this, &quot;Error code: &quot; + response.code(), 
                 Toast.LENGTH_SHORT).show();
                  } else {
                      String trialvalue = trialedCity.getText().toString().trim();
                      Intent resultIntent = new Intent();
                      resultIntent.putExtra(&quot;trialValue&quot;,trialvalue);
  
                      Location location = new Location(trialvalue);
                      locationViewModel.insert(location);
                      setResult(RESULT_OK,resultIntent);
                      finish();
                  }
              }
  
              @Override
              public void onFailure(Call&lt;Example&gt; call, Throwable t) {
                  Toast.makeText(LocationsActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
              }
          });
      }
  
      @Override
      public boolean onSupportNavigateUp() {
          finish();
          return true;
      }
  }
  </code></pre>
  <p><strong>ViewModel Class</strong></p>
  <pre><code>package com.example.smweather;
  
  import android.app.Application;
  
  import java.util.List; 
  
  import androidx.annotation.NonNull;
  import androidx.lifecycle.AndroidViewModel;
  import androidx.lifecycle.LiveData;
  
  public class LocationViewModel extends AndroidViewModel {
  private LocationRepository repository;
  private LiveData&lt;List&lt;Location&gt;&gt; allLocations;
  
  public LocationViewModel(@NonNull Application application) {
      super(application);
      repository = new LocationRepository(application);
      allLocations = repository.getAllLocations();
  }
  
  public void insert(Location location) {
      repository.insert(location);
  }
  
  public void update(Location location) {
      repository.update(location);
  }
  
  public void delete(Location location) {
      repository.delete(location);
  }
  
  public void deleteAllLocations() {
      repository.deleteAllLocations();
  }
  
  public LiveData&lt;List&lt;Location&gt;&gt; getAllLocations() {
      return allLocations;
  }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/PZ3mb.png" rel="nofollow noreferrer">In the first image The list of database should show below the search button</a></p>
  <p><a href="https://i.stack.imgur.com/F1bFU.png" rel="nofollow noreferrer">The list only shows when the editText field is clicked</a></p>
  <p>Please see the above pictures for better understanding.</p>