-1

Trying to get a Fragment to load in Gingerbread using android.support.v4.app but I keep getting the following error:

The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Welcome)

My Welcome class extends Fragment, not sure what I am doing wrong here?

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        loadfrag();
    }

    private void loadfrag() {
        Welcome frag = new Welcome();
        android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.flactivity_main, frag); **<--- line with error**
        transaction.commit();
    }
}


import android.support.v4.app.Fragment;

public class Welcome extends Fragment{
    private final String TAG = this.getClass().getSimpleName();
    private ViewGroup mrootview;
    private Activity mactivity;
    private Context mcontext;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        //mrootview = (ViewGroup) 
        return inflater.inflate(R.layout.welcome, container, false);

    }
}
parsley72
  • 8,449
  • 8
  • 65
  • 98
K3NN3TH
  • 1,458
  • 2
  • 19
  • 31
  • Possible duplicate : http://stackoverflow.com/questions/11619573/fragment-add-or-replace-not-working – TooCool Oct 03 '14 at 21:02

1 Answers1

3

Instead of getFragmentManager() method use getSupportFragmentManager().