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.
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
|
show 1 more comment
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.
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
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
|
show 1 more comment
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.
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
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.
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
android android-fragments supportmapfragment
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
|
show 1 more comment
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
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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