Error in fragment

I am writing programs with a simple snippet and I got an error as shown below:

FrameLayout fl=new FrameLayout(this);
fl.setId(0x1024);

setContentView(fl);
FragmentTransaction ftransc=getFragmentManager().beginTransaction();
FragmentTest2 myFragment=new FragmentTest2();
ftransc.add(fl.getId(), myFragment, "FirstFragment");
ftransc.commit();

In the method, addI get a red square line, and the following error shows:

A method add(int, Fragment, Stringin a type is FragmentTransactionnot applicable to arguments (int, FragmentTest2, String).

What am I doing wrong?

+2
source share
1 answer

This problem usually occurs when you mix compatibility pack Fragmentand Android Fragment. If you are trying to use the Compatibility Snippet, make sure you import android.support.v4.app.Fragment, otherwise make sure you import android.app.Fragment. Do the same with FragmentTransaction.

+5
source

All Articles