Thursday 15 January 2015

java - Checking current opened fragment position while using DrawerLayout -


I am using an Android drawer layout to display the slide menu. I'm using a single activity and 5 to 6 pieces to show them in the drawer layout menu. But I have a small problem. "How do I check which piece is currently visible, if the user has The menu item has to be selected which matches the already opened piece, which is currently re-creating the piece and displaying it is not good. The function that is triggered When the menu item is clicked:

  Private zero selection item {fragment transaction feat = sociable support manager (). BeginTransaction (); // position position switch (position } {Case 0: Feet (RD content_frame, volume1); brake; case1: feet. (RID.Content_frame, section 2); break; case 2: foot .Replay (RIDcontent_frame, Section 3); brake;} ft.commit (); mDrawerList.setItemChecked (position, true); // Close drawer mDrawerLayout.closeDrawer (mDrawerList);}   

What that has opened before you requested piece that he checks I could not make it again? Does it have any way to check through the fragment manager?

I will add to @plato's answer. If you do not already have it, check the question

The answer states that when you add to the piece of your transaction, you represent a special piece Can use a tag. Something like this:

  ft.replace (android.r.id.content, fragment, "MY_FRAGMENT");   

Later if you want check to see that piece, then you can do something like this:

  requested Section segment = (. RequestedFragment) getFragmentManager () findFragmentByTag ("MY_FRAGMENT"); // "My_FRAGMENT" is its tag (fragment.isVisible ()) {// add your code here}   

Hope this will be helpful

No comments:

Post a Comment