Closed jjhesk closed 8 years ago
Hey jjhesk,
Thanks a lot for all the feedback and the use of my library. Please note that my library relies on Fragments extending NavigationFragment (or NavigationListFragment) in order to be able to use the present and dismiss methods. However there should be no stopping you from using other fragment within containers.
I don't seem to have any issues with doing a remove/replace on my container. I just pushed some code that uses a NavigationDrawer as an example. In this code I use NavigationFragments and Fragments and it also uses replace/remove instead of attach/detach. Please take a look at the code in the branch git_issue_3 and let me know if you need some help from that.
If this doesn't help can you please elaborate on what the issue is exactly that you are facing? The point of this manager is to make an instance of one of the managers (and it's root or master-detail fragments), and then start presenting/dismissing fragments from within themselves. Please see my ReadMe and the SampleFragment for how to push/pop fragments on and off the stack.
please hold on this issue. I need to do some more extensive testing on my app to find out where its happening.
Alright will do. If there is anything I can do to help let me know. Here is the code snippet that I use for the add/replace/remove of the Normal Fragment/Navigation Fragment.
// START BLOCK onNavigationItemSelected
if (id == R.id.nav_camera) {
// Using a NavigationFragment
initialNavigationFragmentManager(SampleFragment.newInstance("Nav Camera", 0), "Camera");
}
else if (id == R.id.nav_gallery) {
// Using a support v4 Fragment
initialNavigationFragmentManager(NonNavigationFragment.newInstance("Non-Nav Gallery"), "Gallery");
}
else if (id == R.id.nav_slideshow) {
// Using a NavigationFragment
initialNavigationFragmentManager(SampleFragment.newInstance("Nav Slideshow", 0), "Slideshow");
}
else if (id == R.id.nav_manage) {
// Using a support v4 Fragment
initialNavigationFragmentManager(NonNavigationFragment.newInstance("Non-Nav Manage"), "Gallery");
}
// END BLOCK FROM onNavigationItemSelected
// How to use replace/add
private int targetHomeFrame() {
return R.id.frag_container;
}
private Fragment mVisibleFragment;
/**
* require android-support-v4 import and the regular android fragment
*
* @param fragment the unknown typed fragment
* @param title the string in title
* @param oldFragment the previous fragment
* @param closeDrawer if it needs to close the drawer after the new fragment has been rendered
*/
public void setFragment(Fragment fragment, String title, @Nullable Fragment oldFragment, boolean closeDrawer) {
if (title != null) {
setTitle(title);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (oldFragment != null && oldFragment != fragment)
ft.remove(oldFragment);
ft.replace(targetHomeFrame(), fragment).commit();
mVisibleFragment = fragment;
}
private String mSingleStackNavigationManagerFragmentTag;
public void initialNavigationFragmentManager(Fragment firstFragment, @Nullable String title) {
if (firstFragment instanceof NavigationFragment) {
SingleStackNavigationManagerFragment navManager = SingleStackNavigationManagerFragment.newInstance((INavigationFragment)firstFragment);
setFragment(navManager, title, mVisibleFragment, false);
}
else if (firstFragment instanceof Fragment) {
setFragment(firstFragment, title, mVisibleFragment, false);
}
}
thanks you! you have solved this problem handsomely. I have i think its a good idea to add this piece into your sample demonstration
Thanks jj,
I have merged in the NavigationDrawerExample into the main project.
good work! There is an issue happened from switching between Fragment and NavigationFragment. I was running my code like so
at the end it doesnt seems to support switching between fragment and the navigationfragment at the same framelayout.