0

I am trying to call a class whıch extends fragment from an activity class with startActivity() . It returns me cannot be cast to android.app.activity error. I am confused how can I open fragment vıew from activity.

1 Answers1

1

In the activity, you create an transaction to replace a fragment by another:

    FragmentSelectDate myFragment = new FragmentSelectDate();
    myFragment.setArguments(getIntent().getExtras());
    FragmentTransaction transaction = getSupportFragmentManager()
            .beginTransaction();
    transaction.replace(R.id.containerMain, myFragment,
                "FragmentSelectDate");
    transaction.addToBackStack(null);
    transaction.commit();
roberth
  • 924
  • 9
  • 17
  • if you were not using supportFragment then call getFragmentManger() – NoXSaeeD Jul 13 '14 at 13:35
  • both getsupportfragmentmanager and getfragmentmanager cannot be resolved sınce my first class extends activity. also what is R.id.containerMain ? – user3834286 Jul 13 '14 at 13:39
  • @user3834286, the activity where you use getSupportFragmentManager has to extend "FragmentActivity". R.id.containerMain is a , that I placed in the Activity's layout (.XML). So the Activity has a layout (.XML), that holds a FrameLayout (the container for the fragment). You can have more fragments in 1 activity-layout) – roberth Jul 14 '14 at 14:42