简体   繁体   中英

Calling fragment from activity

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM