Get the current fragment in Android

Nega developer

I'm using a NavigationDrawer Activity (predefined view in AndroidStudio) and I need to put (and get) the current fragment to switch between fragments.

I saw in some places to put visible and hidden the fragments but I have more than 3 so I need to identify all the fragments before switch between thems.

How can I solved? I just only find to set Tags at the moment to be displayed or set the visibility.

MeshBoy

When you add the fragment, you should use a tag

fragTrans.replace(android.R.id.content, myFragment, "SearchingFrag");

So that later if you want to check if the fragment is visible:

 MyFragment Frag =      
 (MyFragment)getFragmentManager().findFragmentByTag("SearchingFrag");
   if (Frag.isVisible()) {
     // add your code 
   }

if you want more help inform me hope you got an idea from my answer

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android get ID of current fragment

From Dev

Android get ID of current fragment

From Dev

Get current fragment color

From Java

Android Navigation Architecture Component - Get current visible fragment

From Dev

Get info of current visible fragment(s) in android dumpsys

From Dev

Android: Not able to get current location in Google Map fragment

From Dev

Get current index in fragment of ViewPager

From Dev

Replace current Fragment in ViewPager on Android

From Dev

Android Get VersionName in Fragment

From Dev

Android Get VersionName in Fragment

From Dev

Get Current Visible Fragment From Activity

From Dev

Not able to get current location in Google Map fragment

From Dev

How to get the current fragment when using FragmentStatePagerAdapter

From Dev

Android - How to hide menu option for current fragment

From Dev

Android Transform the current Fragment Class to Activity Class

From Dev

Android Transform the current Fragment Class to Activity Class

From Dev

home fragment partially visible with mixed view of current fragment android studio

From Java

Android fragment get covered by another fragment

From Dev

Android Get current month

From Dev

Get the Application Context In Fragment In Android?

From Dev

Android get actual instance of a Fragment

From Dev

Android: Get fragment from PagerAdapter

From Dev

Android get tabLayout from a fragment

From Dev

Get current latitude and longitude android

From Java

Android get current Locale, not default

From Java

How to get current location in Android

From Dev

Get current country in Android - traveling

From Dev

How to get current ringtone in Android?

From Dev

Get Current Activity in Espresso android

Related Related

HotTag

Archive