Why the multiple SupportMapFragment overlap in different fragment in Android?











up vote
0
down vote

favorite












I am new to developing Android Google Map , I use the two SupportMapFragment in different Fragment-1 and Fragment-2 respectively.



First , I add the two fragment to BackStack. Before showing the any fragment , I will hide the all fragment first.



I want these two fragment were live at the same times , so I did not use replace or remove any fragment. Forex-sample , when the fragment2 is hiding , but it still do something at the background.



I open the Fragment-1 at first and turn to the Fragment-2 , and then back to the Fragment-1. The Fragment-1 show the overlap like the following picture.



enter image description here



I have try to hide the one of the Fragment-2, but it is not working.



IN MainActivity , I manager my fragment.



In onCreate() , I will call following function:



public void initStartFragment(){

fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.addToBackStack(Fragment1.getClass().getName()).commit();

fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.addToBackStack(Fragment2.getClass().getName()).commit();
}


@Override
public void onClick(View v) {

FragmentTransaction mFragmentTransaction = mManager.beginTransaction();
hideFragment(mFragmentTransaction);

if(v.getId() == R.id.dive_learning_btn){

if (fragment1 == null) {
fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.commit();
}
mFragmentTransaction.show(fragment1)
.commit();

}else if(v.getId() == R.id.expect_setting_btn){

if (fragment2== null) {
fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.commit();
}
mFragmentTransaction.show(fragment2)
.commit();

}
}


Before show the fragment, I will hide all fragment first:



public void hideFragment(FragmentTransaction ft) {
//if fragment noy null , hide it.
if (fragment1 != null) {
ft.hide(fragment1 );
}
if (fragment2 != null) {
ft.hide(fragment12);
}
}


I want these two fragment were live at the same times , so I did not use replace or remove any fragment.



Why this condition happened ? Did I missing something ?



Can someone help me ?



Thanks in advance.










share|improve this question
























  • Can you put your fragment manager code? please
    – Daniel Carreto
    Nov 10 at 1:00










  • @DanielCarreto HI , I have edit and add the code of fragment manager.
    – Wun
    Nov 10 at 1:07










  • Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
    – Daniel Carreto
    Nov 10 at 1:09










  • @DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
    – Wun
    Nov 10 at 1:12










  • okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
    – Daniel Carreto
    Nov 10 at 1:16















up vote
0
down vote

favorite












I am new to developing Android Google Map , I use the two SupportMapFragment in different Fragment-1 and Fragment-2 respectively.



First , I add the two fragment to BackStack. Before showing the any fragment , I will hide the all fragment first.



I want these two fragment were live at the same times , so I did not use replace or remove any fragment. Forex-sample , when the fragment2 is hiding , but it still do something at the background.



I open the Fragment-1 at first and turn to the Fragment-2 , and then back to the Fragment-1. The Fragment-1 show the overlap like the following picture.



enter image description here



I have try to hide the one of the Fragment-2, but it is not working.



IN MainActivity , I manager my fragment.



In onCreate() , I will call following function:



public void initStartFragment(){

fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.addToBackStack(Fragment1.getClass().getName()).commit();

fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.addToBackStack(Fragment2.getClass().getName()).commit();
}


@Override
public void onClick(View v) {

FragmentTransaction mFragmentTransaction = mManager.beginTransaction();
hideFragment(mFragmentTransaction);

if(v.getId() == R.id.dive_learning_btn){

if (fragment1 == null) {
fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.commit();
}
mFragmentTransaction.show(fragment1)
.commit();

}else if(v.getId() == R.id.expect_setting_btn){

if (fragment2== null) {
fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.commit();
}
mFragmentTransaction.show(fragment2)
.commit();

}
}


Before show the fragment, I will hide all fragment first:



public void hideFragment(FragmentTransaction ft) {
//if fragment noy null , hide it.
if (fragment1 != null) {
ft.hide(fragment1 );
}
if (fragment2 != null) {
ft.hide(fragment12);
}
}


I want these two fragment were live at the same times , so I did not use replace or remove any fragment.



Why this condition happened ? Did I missing something ?



Can someone help me ?



Thanks in advance.










share|improve this question
























  • Can you put your fragment manager code? please
    – Daniel Carreto
    Nov 10 at 1:00










  • @DanielCarreto HI , I have edit and add the code of fragment manager.
    – Wun
    Nov 10 at 1:07










  • Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
    – Daniel Carreto
    Nov 10 at 1:09










  • @DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
    – Wun
    Nov 10 at 1:12










  • okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
    – Daniel Carreto
    Nov 10 at 1:16













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am new to developing Android Google Map , I use the two SupportMapFragment in different Fragment-1 and Fragment-2 respectively.



First , I add the two fragment to BackStack. Before showing the any fragment , I will hide the all fragment first.



I want these two fragment were live at the same times , so I did not use replace or remove any fragment. Forex-sample , when the fragment2 is hiding , but it still do something at the background.



I open the Fragment-1 at first and turn to the Fragment-2 , and then back to the Fragment-1. The Fragment-1 show the overlap like the following picture.



enter image description here



I have try to hide the one of the Fragment-2, but it is not working.



IN MainActivity , I manager my fragment.



In onCreate() , I will call following function:



public void initStartFragment(){

fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.addToBackStack(Fragment1.getClass().getName()).commit();

fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.addToBackStack(Fragment2.getClass().getName()).commit();
}


@Override
public void onClick(View v) {

FragmentTransaction mFragmentTransaction = mManager.beginTransaction();
hideFragment(mFragmentTransaction);

if(v.getId() == R.id.dive_learning_btn){

if (fragment1 == null) {
fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.commit();
}
mFragmentTransaction.show(fragment1)
.commit();

}else if(v.getId() == R.id.expect_setting_btn){

if (fragment2== null) {
fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.commit();
}
mFragmentTransaction.show(fragment2)
.commit();

}
}


Before show the fragment, I will hide all fragment first:



public void hideFragment(FragmentTransaction ft) {
//if fragment noy null , hide it.
if (fragment1 != null) {
ft.hide(fragment1 );
}
if (fragment2 != null) {
ft.hide(fragment12);
}
}


I want these two fragment were live at the same times , so I did not use replace or remove any fragment.



Why this condition happened ? Did I missing something ?



Can someone help me ?



Thanks in advance.










share|improve this question















I am new to developing Android Google Map , I use the two SupportMapFragment in different Fragment-1 and Fragment-2 respectively.



First , I add the two fragment to BackStack. Before showing the any fragment , I will hide the all fragment first.



I want these two fragment were live at the same times , so I did not use replace or remove any fragment. Forex-sample , when the fragment2 is hiding , but it still do something at the background.



I open the Fragment-1 at first and turn to the Fragment-2 , and then back to the Fragment-1. The Fragment-1 show the overlap like the following picture.



enter image description here



I have try to hide the one of the Fragment-2, but it is not working.



IN MainActivity , I manager my fragment.



In onCreate() , I will call following function:



public void initStartFragment(){

fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.addToBackStack(Fragment1.getClass().getName()).commit();

fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.addToBackStack(Fragment2.getClass().getName()).commit();
}


@Override
public void onClick(View v) {

FragmentTransaction mFragmentTransaction = mManager.beginTransaction();
hideFragment(mFragmentTransaction);

if(v.getId() == R.id.dive_learning_btn){

if (fragment1 == null) {
fragment1= new Fragment1();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment1)
.commit();
}
mFragmentTransaction.show(fragment1)
.commit();

}else if(v.getId() == R.id.expect_setting_btn){

if (fragment2== null) {
fragment2= new Fragment2();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_layout, fragment2)
.commit();
}
mFragmentTransaction.show(fragment2)
.commit();

}
}


Before show the fragment, I will hide all fragment first:



public void hideFragment(FragmentTransaction ft) {
//if fragment noy null , hide it.
if (fragment1 != null) {
ft.hide(fragment1 );
}
if (fragment2 != null) {
ft.hide(fragment12);
}
}


I want these two fragment were live at the same times , so I did not use replace or remove any fragment.



Why this condition happened ? Did I missing something ?



Can someone help me ?



Thanks in advance.







android android-fragments supportmapfragment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 1:21

























asked Nov 10 at 0:57









Wun

2,47253273




2,47253273












  • Can you put your fragment manager code? please
    – Daniel Carreto
    Nov 10 at 1:00










  • @DanielCarreto HI , I have edit and add the code of fragment manager.
    – Wun
    Nov 10 at 1:07










  • Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
    – Daniel Carreto
    Nov 10 at 1:09










  • @DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
    – Wun
    Nov 10 at 1:12










  • okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
    – Daniel Carreto
    Nov 10 at 1:16


















  • Can you put your fragment manager code? please
    – Daniel Carreto
    Nov 10 at 1:00










  • @DanielCarreto HI , I have edit and add the code of fragment manager.
    – Wun
    Nov 10 at 1:07










  • Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
    – Daniel Carreto
    Nov 10 at 1:09










  • @DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
    – Wun
    Nov 10 at 1:12










  • okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
    – Daniel Carreto
    Nov 10 at 1:16
















Can you put your fragment manager code? please
– Daniel Carreto
Nov 10 at 1:00




Can you put your fragment manager code? please
– Daniel Carreto
Nov 10 at 1:00












@DanielCarreto HI , I have edit and add the code of fragment manager.
– Wun
Nov 10 at 1:07




@DanielCarreto HI , I have edit and add the code of fragment manager.
– Wun
Nov 10 at 1:07












Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
– Daniel Carreto
Nov 10 at 1:09




Thanks, chance add method to replace in your second fragment, with that you avoid the overlay, and to hide switch with mFragmentTransaction.show(fragment2) .commit(); and mFragmentTransaction.hide(fragment2) .commit();
– Daniel Carreto
Nov 10 at 1:09












@DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
– Wun
Nov 10 at 1:12




@DanielCarreto But I want these two fragment were live at the same times , so I did not use replace or remove any fragment.
– Wun
Nov 10 at 1:12












okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
– Daniel Carreto
Nov 10 at 1:16




okay, just change ft.hide(fragment1 ); with mFragmentTransaction.hide(fragment2) .commit(); to show/hide fragments
– Daniel Carreto
Nov 10 at 1:16

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235098%2fwhy-the-multiple-supportmapfragment-overlap-in-different-fragment-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235098%2fwhy-the-multiple-supportmapfragment-overlap-in-different-fragment-in-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff