嘿,我有一个导航抽屉,每个元素都会打开一个片段。现在我想打开最后一个片段,如果我按下后退按钮。我使用这个.addBackStack(null)方法,但当我按回然后我没有内容,当我再次按下后面我有我需要的片段。我怎样才能摆脱这种黑色内容? 我改变了我的片段:
@Override
public void onNavigationDrawerItemSelected(final int position) {
// update the main content by replacing fragments
final FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1))
.addToBackStack(null)
.commit();
if(position==0)
{
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
fragmentManager.beginTransaction()
.replace(R.id.container, KedvencekFragment.newInstance(position + 1))
.addToBackStack(null)
.commit();
}
}, 250);
}