我使用.replace()替换旧的片段用新的,但在这一刻我不会如何使用片段的.replace()到mapsFragment。
思想? 我可以用替换吗?如果我可以'使用它,我可以使用什么?
这是我此时的代码。 (.replace()不工作)
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
mapsFragment fragM = null;
Fragment frag = null;
switch (position) {
case 0: //Home
mTitle = "Maps";
fragM = new mapsFragment();
break;
case 1: //Query utente
mTitle = "Section 2";
break;
case 2: //Query Amministratore
mTitle = "Section 3";
break;
}
if (position != 3) {
if(position==0){
fragmentManager.beginTransaction()
.replace(R.id.container, fragM)
.commit();
}else {
fragmentManager.beginTransaction()
.replace(R.id.container, frag)
.commit();
}
答案 0 :(得分:0)
我找到了解决方案:link where i have found it
这是特别的代码:
if(position==0){
FragmentTransaction mTransaction = getSupportFragmentManager()
.beginTransaction();
SupportMapFragment mFRaFragment = new mapsFragment();
mTransaction.replace(R.id.container, mFRaFragment);
mTransaction.commit();
}else {