I have a list Fragment (importing the v4 support library, build target is 2.3.3 api 11) and the following problem in my code that was working fine when the target was 3.0 and I didn't use the library.
Fragment frag1 = new ExampleFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.contentframe, frag1);
ft.commit();
Now I'm getting the compile error that
"Type mismatch: cannot convert from ExampleFragment to Fragment"
and it tells me to change the "Fragment" to ExampleFragment (e.g.)
ExamplesFragment frag1 = new ExamplesFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.contentframe, frag1);
ft.commit();
Then I have a problem that the ft.replace command has an error:
The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Fragment_PVAnn)
and it tells me to change the ExamplesFragment in the first line back to just Fragment and so the circle goes round and around
You should use
getActivity().getSupportFragmentManager()
If that is still giving you problems, then makre sure that your Activity extends FragmentActivity
.
If that is still giving you problems,
support.v4.*
, not android.*
.You have to make sure that when you extend Fragment
that you are extending the Fragment
that is in the v4
package space. Check your imports for Fragment
, FragmentActivity
, etc, and if you see them imported WITHOUT .v4 in the package name, then it is wrong.
Also, if you set the android library for the project to be 2.3 and not 4.0.x then you'll quickly see if you are using the incorrect classes, because you'll get compile errors, which can be fixed by using the v4 classes from the android support jar (which hopefully you've included in your project as well)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With