fneron
fneron

Reputation: 1097

ActionBar tabs with FragmentActivity

class MyTabsListener implements ActionBar.TabListener {
    public Fragment fragment;

    public MyTabsListener(Fragment fragment) {
        this.fragment = fragment;
    }

    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        Toast.makeText(DashboardFragmentActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
    }

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(R.id.fragment_container, fragment);
    }

    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
    }

Is it possible instead to change Fragment to FragmentActivity? How would you implement this, I'm confuse about those two.

Upvotes: 0

Views: 558

Answers (1)

Archie.bpgc
Archie.bpgc

Reputation: 24012

Fragments are always used in FragmentActivities, so you cannot replace a Fragment with a FragmentActivity, because nested activities are deprecated.

And you always have an option to use getActivity(); in the Fragments to get the parent Activity, so for whatever reason you wanted to replace Fragment with FragmentActivity it can be achieved with just Fragment.

Upvotes: 2

Related Questions