xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
In regular fragment it goes like this:
mFragment = (mFragment) (getSupportFragmentManager().findFragmentById(R.id.mFragment));
mFragment.getView().setVisibility(View.INVISIBLE);
In Google map fragment:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment)).getMap();
But how can I set map fragment visibility progrematically?
Can't do it like others fragment.
Both the answer By
@David
and@ferdy182
are right but they don't told the context.if you hide/show fragment Programmatically then use
@ferdy182
and if you want to hide/show fragment which is in xml. you should follow@David
Let me explain
If you are having a single frameLayout in xml and you want to replace the other fragment in that particular one after another. use this code to add all fragment . they will be place on one another.
hide all other fragment except which you want to show.
Benefit These fragment work like form in c#. Forum.show and forum.hide(); . Where there current state remain their. these fragment don't call again and again. A problem here i solve it using this technique. 2nd Method
when you are having multiple frameLayout or fragment in xml . you can hide that particular by getting its id.
Codes
// to show fragment when it is hidden
// to hide fragment
You can do:
to show it:
Only that works for me :
Instead of creating a
SupportMapFragment
in xml, there could be another approach in which we can define container forSupportMapFragment
in xml and then load map from class.In XML, let say container is
FrameLayout
-In my java class which is a
Fragment
, I have created two methods to show and hide map. I used detach and it depends on need. We can also use hide instead of detach.Simple as this: