Im trying to switch fragments using the example here:
http://developer.android.com/guide/components/fragments.html
But it does not work:
Fragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
I get the error:
The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Fragment)
So I fix this with:
android.app.Fragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
and get another error saying that ExampleFragment has teh wrong type, so I change it to:
ExampleFragment newFragment = new ExampleFragment();
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
And it all just keeps going round in loops, whats the fix?
You need to add the support library to the project. That should fix your issues. Undo the code changes you made… and in eclipse, right click (or option click depending on your machine) the project and go to Android Tools > Add Support Library…
Clean and rebuild the project… should fix all your errors.