我在旋转屏幕时更新RecyclerView时遇到了问题。通过单击fab按钮,我将显示带有输入字段的对话框片段。然后,当我旋转屏幕并保存数据时,我的RecyclerView没有更新。我正在onCreate方法中设置适配器。我应该再旋转一次,以便看到新的数据。如何才能解决这个问题。
提前谢谢。
dataSource = new MyBusinessDataSource(this);
try
{
dataSource.openForRead();
}
catch (SQLException sqlEx)
{
Toast.makeText(MyBusinessMainActivity.this, R.string.sqlite_exception, Toast.LENGTH_SHORT).show();
return;
}
categories = dataSource.getAllCategories();
adapter = new CategoriesAdapter(this, categories);
rv_list_cats.setAdapter(adapter);
dataSource.close();发布于 2015-11-23 12:08:13
您需要在活动或片段中重写您的onConfigurationChanged方法,并在那里更新您的数据。喜欢。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(adapter!=null)
{
categories = dataSource.getAllCategories();
adapter.notifyDataSetChanged();
}
}另外,如果您没有在清单中使用ScreenConfig属性,则如下所示。
android:configChanges="orientation|screenSize"https://stackoverflow.com/questions/33869945
复制相似问题