我正在加载一个RecyclerView基于调用Retrofit和存储在本地SQLite数据库中的数据。
在屏幕旋转时,RecyclerView保持重置。此外,当我收藏一部电影(将电影添加到我的本地房间数据库)时,在某些情况下,我的微调器与要填充到RecyclerView. 下面是我的代码:
public class MainActivity extends AppCompatActivity {
private RecyclerView mMovieResults;
private MyAdapter mMovieResultsAdapter;
private String query;
private String mBaseURL;
private int lastFirstVisiblePosition;
//TODO: How is someone able to load my API Key if I am storing it
private ArrayList<String> mMovieURLS;
private ArrayList<Movie> mMovies;
private List<Movie> mMovieResultsList;
private static final String SPINNER_SELECTION = "SPINNER_SELECTION";
private boolean mIsFavoriteSelected;
private AppDatabase mDb;
private Spinner mSpinner;
private SharedPreferences mPrefs;
private SharedPreferences.Editor mPrefsEditor;
private static Bundle mBundleRecyclerViewState;
private int saved_selection = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("ONCREATE", "ONCREATE");
if (savedInstanceState != null){
saved_selection = savedInstanceState.getInt(SPINNER_SELECTION);
}
if (isOnline()) {
setContentView(R.layout.activity_main);
Stetho.initializeWithDefaults(this);
mDb = AppDatabase.getInstance(getApplicationContext());
mMovieResults = findViewById(R.id.main_recyclerview_image_results);
GridLayoutManager glm = new GridLayoutManager(this, 3);
glm.setOrientation(LinearLayoutManager.VERTICAL);
mMovieResults.setLayoutManager(glm);
mMovieURLS = new ArrayList<>();
mMovies = new ArrayList<>();
mMovieResultsList = new ArrayList<>();
mMovieResultsAdapter = new MyAdapter(mMovieResultsList);
mMovieResults.setAdapter(mMovieResultsAdapter);
mDb = AppDatabase.getInstance(getApplicationContext());
mPrefs = getSharedPreferences("prefs", MODE_PRIVATE);
慕尼黑的夜晚无繁华
墨色风雨
相关分类