I am using Fragment manager in navigation drawer in android studio.I typed the following code as
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(content_frame, fragment).commit();
It shows red line below fragment in above code.
The screenshot is also uploaded.enter image description here
Change getFragmentManager() for getSupportFragmentManager()and import supportV4
Related
I followed this tutorial: https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer
Now Im at this point:
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
// Highlight the selected item has been done by NavigationView
menuItem.setChecked(true);
// Set action bar title
setTitle(menuItem.getTitle());
// Close the navigation drawer
mDrawer.closeDrawers();
My Problem is that this line..
FragmentManager fragmentManager = getSupportFragmentManager();
show me an error : incompatible types. Required android.app.FragmentManager Found: android.support.v4.app.FragmentManager.
I saw some posts but they doesn't work for me.
I extend my class with AppCompatActivity, tried FragmentActivity but this doesn't work.
If I change FragmentManager to android.support.v4.app.FragmentManager, the error disappear but then
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit(); shows: Wrong 2nd argument type.Found:'android.app.Fragment',required'android.support.v4.app.Fragment'
Pls help me :/
Change
import android.app.Fragment;
import android.app.FragmentManager;
to
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
in every class. you are facing problems because in your Fragment creation class you are using support v4 fragment and in your MainActivity class you are inflating as a simple fragment.
You also need to change getFragmentManager() to
getSupportFragmentManager(), and make sure they're extending a FragmentActivity class.
Hope it will help you.
I am building an Expense Keeping app with React-Native on Android. Below is the UI flow chart of my app:
I wish to use the Drawer to navigate between top level scenes (shown in dark red).
In the Settings scene, there are options that require to navigate to a group of 2nd level scenes which can only navigate back to the Settings scene (shown in blue).
I want my Navigation bar to persist across scene transitions, so I am using the navigationBar props of the <Navigator> component.
Using a single <Navigator> as the top component in my app and manage all the scenes and routes with it is an obvious solution but this way it is harder to manage the "levels" of scenes.
I would like to know if there are any other better ways to structure the <Navigator> in my app, perhaps nesting navigators?
I know this is an old question, but it is still relevant and just to keep this up-to-date, use React-Navigation (Warning: requires some learning and practice). You can use this example. Look out for the navigation tree in that. It is similar to what the question needs.
Have you tried react-native-router-flux component?
You can using Fragment.
First: In Activity. You create Navigatior.
in xml of Activity have:
<DrawerLayout>
<Toolbar> or (Control Home of you)
<FrameLayout id="content_main">
Then: You create SettingFragment extend Fragment
HomeFragment extend Fragment
ExpansesFragment extend Fragment
import support.v4.Fragment
In Activity extend Activity
onCreate:
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, HomeFragment)
.commit();
On Drawer. event Onclick
Home
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, HomeFragment)
.commit();
Expenses
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, ExpensesFragment)
.commit();
Category
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, CategoryFragment)
.commit();
I am using drawer navigation where all pages are fragments.How to open fragment page using button on another fragment ?
Use FragmentManager like
call this method button onclick method
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
you have to replace you fragment manager id instead of R.id.frame_container
I hope this one will help to you :)
I am trying to get an application working that uses the ActionBar slider with a TabHost. I am replacing the current Fragment with another when a menu item is selected.
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
The problem that I am getting is that I am unable to replace a fragment with a FramgentActivity which contains a TabHost. So my question is, is it possible to put a FragmentedTabHost inside a Fragment (instead of a FragmentedActivity)? If so, how would you implement it?
I've followed Google's recommended implementation of the Navigation Drawer and now have an introductory Fragment and Map fragment that I transition between. The drawer worked smoothly until I added ActionBarSherlock to my project. Now, when the home (original fragment) is selected the menu is delayed closing and I get an annoying flash before the home fragment appears.
The fragment transaction is handled by:
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.replace(R.id.content_frame, fragment, null)
.commit();
Any suggestions are welcome.