我想使用Navigation Drawer
来更改新闻部分。我想在每次单击Navigation Drawer
中的项目时重新初始化加载程序。但是我找不到正确的方法。我试图利用 活动生命周期 ,但是找不到正确的方法。
这是部分代码:
当我单击Navigation Drawer
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.headlines: {
section = null;
}
break;
case R.id.world: {
section = "world";
}
break;
case R.id.business: {
section = "business";
}
break;
case R.id.community: {
section = "community";
}
break;
case R.id.sport: {
section = "sport";
}
break;
case R.id.art: {
section = "artanddesign";
}
break;
case R.id.culture: {
section = "culture";
}
break;
default:
section = "culture";
break;
}
item.setChecked(true);
mDrawerLayout.closeDrawers();
return true;
}
@Override
protected void onResume() {
if (isConnected(this)) {
getLoaderManager().initLoader(0, null, this).forceLoad();
} else {
emptyStateView.setText(R.string.no_internet);
loadingIndicator.setVisibility(View.GONE);
}
super.onResume();
}