Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment, String tag);

Source Link

Document

Add a fragment to the activity state.

Usage

From source file:com.android.settings.applications.BackgroundCheckSummary.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // initialize the inflater
    mInflater = inflater;/*  w  w  w . j  a  va 2s.com*/

    View rootView = mInflater.inflate(R.layout.background_check_summary, container, false);

    // We have to do this now because PreferenceFrameLayout looks at it
    // only when the view is added.
    if (container instanceof PreferenceFrameLayout) {
        ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
    }

    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    ft.add(R.id.appops_content, new AppOpsCategory(AppOpsState.RUN_IN_BACKGROUND_TEMPLATE, true), "appops");
    ft.commitAllowingStateLoss();

    return rootView;
}

From source file:com.samsung.msca.samsungvr.sampleapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocalBroadcastManager = LocalBroadcastManager.getInstance(this);
    mFragmentManager = getFragmentManager();

    IntentFilter filter = new IntentFilter();
    filter.addAction(Util.ACTION_SHOW_LOGIN_PAGE);
    filter.addAction(Util.ACTION_SHOW_LOGGED_IN_PAGE);

    mLocalBroadcastManager.registerReceiver(mLocalBroadcastReceiver, filter);

    setContentView(R.layout.activity_main);

    if (null != savedInstanceState) {
        return;// w ww  . j  av a2s. c  o  m
    }

    FragmentTransaction ft = mFragmentManager.beginTransaction();

    ft.add(android.R.id.content, LoginFragment.newFragment(), LoginFragment.TAG);
    ft.commitAllowingStateLoss();
}

From source file:com.explovia.mapdemo.ProgrammaticDemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // It isn't possible to set a fragment's id programmatically so we set a tag instead and
    // search for it using that.
    mMapFragment = (MapFragment) getFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);

    // We only create a fragment if it doesn't already exist.
    if (mMapFragment == null) {
        // To programmatically add the map, we first create a SupportMapFragment.
        mMapFragment = MapFragment.newInstance();

        // Then we add it using a FragmentTransaction.
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.add(android.R.id.content, mMapFragment, MAP_FRAGMENT_TAG);
        fragmentTransaction.commit();/*from  w  ww .  j  a  v  a 2  s. c  o  m*/
    }

    // We can't be guaranteed that the map is available because Google Play services might
    // not be available.
    setUpMapIfNeeded();
}

From source file:com.tct.mail.browse.EmlViewerActivity.java

private void doCreate(Bundle savedInstanceState) {
    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();
    if (savedInstanceState == null) {
        if (Intent.ACTION_VIEW.equals(action) && MimeType.isEmlMimeType(type)) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.root, EmlMessageViewFragment.newInstance(intent.getData(), mAccountUri),
                    FRAGMENT_TAG);//from  ww  w . j a v a 2 s  . c  o m
            transaction.commit();
            Analytics.getInstance().sendEvent("eml_viewer", null, null, 0);
        } else {
            LogUtils.wtf(LOG_TAG, "Entered EmlViewerActivity with wrong intent action or type: %s, %s", action,
                    type);
            finish(); // we should not be here. bail out. bail out.
            return;
        }
    }
}

From source file:com.google.android.apps.santatracker.doodles.PineappleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view);

    // Check for game direct launch
    DoodleConfig config;//from  w  w w. j a  v  a2 s .c o  m
    if (getIntent() != null && getIntent().hasExtra(LaunchDecisionMaker.START_GAME_KEY)) {
        config = new DoodleConfig(getIntent().getExtras(), null);
    } else {
        throw new IllegalStateException("Extra START_GAME_KEY required");
    }

    // [ANALYTICS]
    mAnalytics = FirebaseAnalytics.getInstance(this);
    String gameKey = getIntent().getStringExtra(LaunchDecisionMaker.START_GAME_KEY);
    switch (gameKey) {
    case LaunchDecisionMaker.WATERPOLO_GAME_VALUE:
        MeasurementManager.recordScreenView(mAnalytics, getString(R.string.analytics_screen_waterpolo));
        break;
    case LaunchDecisionMaker.RUNNING_GAME_VALUE:
        MeasurementManager.recordScreenView(mAnalytics, getString(R.string.analytics_screen_running));
        break;
    case LaunchDecisionMaker.SWIMMING_GAME_VALUE:
        MeasurementManager.recordScreenView(mAnalytics, getString(R.string.analytics_screen_swimming));
        break;
    }

    appInvitesFragment = AppInvitesFragment.getInstance(this);

    logger = new PineappleDebugLogger();
    Fragment fragment = LaunchDecisionMaker.makeFragment(this, config, logger);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.activity_wrapper, fragment, "menu");
    fragmentTransaction.commit();
}

From source file:com.liferay.social.activity.MainActivity.java

public void onCreate(Bundle state) {
    super.onCreate(state);

    setContentView(R.layout.main);/*w w  w .  j a va2s.c  om*/

    _drawer = (DrawerLayout) findViewById(R.id.drawer);

    ListView menu = (ListView) findViewById(R.id.menu);
    String[] menuItems = getResources().getStringArray(R.array.menu_items);

    menu.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuItems));

    menu.setOnItemClickListener(this);

    FragmentManager manager = getFragmentManager();
    Fragment fragment = manager.findFragmentByTag(UsersFragment.TAG);

    if (fragment == null) {
        FragmentTransaction transaction = manager.beginTransaction();

        transaction.add(R.id.right_fragment, new UsersFragment(), UsersFragment.TAG);

        transaction.commit();
    }
}

From source file:com.android.mail.browse.EmlViewerActivity.java

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

    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();
    mAccountUri = intent.getParcelableExtra(EXTRA_ACCOUNT_URI);

    if (savedInstanceState == null) {
        if (Intent.ACTION_VIEW.equals(action) && MimeType.isEmlMimeType(type)) {
            final FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.add(R.id.eml_root, EmlMessageViewFragment.newInstance(intent.getData(), mAccountUri),
                    FRAGMENT_TAG);//  ww w .  j  a  va  2 s  . co m
            transaction.commit();
        } else {
            LogUtils.wtf(LOG_TAG, "Entered EmlViewerActivity with wrong intent action or type: %s, %s", action,
                    type);
            finish(); // we should not be here. bail out. bail out.
            return;
        }
    } else {
        if (savedInstanceState.containsKey(SAVED_ACCOUNT)) {
            mAccount = savedInstanceState.getParcelable(SAVED_ACCOUNT);
        }
    }

    // Account uri will be null if we launched from outside of the app.
    // So just don't load an account at all.
    if (mAccountUri != null) {
        getLoaderManager().initLoader(ACCOUNT_LOADER, Bundle.EMPTY, mAccountLoadCallbacks);
    }
}

From source file:com.ttarn.followme.ContactDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (BuildConfig.DEBUG) {
        // Enable strict mode checks when in debug modes
        Utils.enableStrictMode();//from   w w  w .  j  ava  2  s.  c  o m
    }
    super.onCreate(savedInstanceState);

    // This activity expects to receive an intent that contains the uri of a contact
    if (getIntent() != null) {

        // For OS versions honeycomb and higher use action bar
        if (Utils.hasHoneycomb()) {
            // Enables action bar "up" navigation

            //getActionBar().setDisplayHomeAsUpEnabled(true);
        }

        // Fetch the data Uri from the intent provided to this activity
        final Uri uri = getIntent().getData();

        // Checks to see if fragment has already been added, otherwise adds a new
        // ContactDetailFragment with the Uri provided in the intent
        if (getFragmentManager().findFragmentByTag(TAG) == null) {
            final FragmentTransaction ft = getFragmentManager().beginTransaction();

            // Adds a newly created ContactDetailFragment that is instantiated with the
            // data Uri
            ft.add(android.R.id.content, ContactDetailFragment.newInstance(uri), TAG);
            //ft.show(ContactDetailFragment.newInstance(uri)).addToBackStack(null).commit();
            ft.commit();
        }
    } else {
        // No intent provided, nothing to do so finish()
        finish();
    }
}

From source file:com.jeremy.tripcord.main.TripcordFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_tripcord, container, false);

    listViewTripHistory = (ListView) rootView.findViewById(R.id.list);
    listViewTripHistory.setOverScrollMode(ListView.OVER_SCROLL_NEVER);

    slidingUpPanelLayout = (SlidingUpPanelLayout) rootView.findViewById(R.id.slidingLayout);
    slidingUpPanelLayout.setEnableDragViewTouchEvents(true);

    int mapHeight = getResources().getDimensionPixelSize(R.dimen.map_height);
    slidingUpPanelLayout.setPanelHeight(mapHeight); // you can use different height here
    slidingUpPanelLayout.setScrollableView(listViewTripHistory, mapHeight);

    slidingUpPanelLayout.setPanelSlideListener(this);

    // transparent view at the top of ListView
    transparentView = rootView.findViewById(R.id.transparentView);

    // init header view for ListView
    transparentHeaderView = LayoutInflater.from(getActivity()).inflate(R.layout.transparent_header_view, null,
            false);/* w w  w  . ja  va  2  s .  co m*/
    spaceView = transparentHeaderView.findViewById(R.id.space);

    ArrayList<String> testData = new ArrayList<String>(100);
    for (int i = 0; i < 100; i++) {
        testData.add("Item " + i);
    }
    listViewTripHistory.addHeaderView(transparentHeaderView);
    listViewTripHistory
            .setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.simple_list_item, testData));
    listViewTripHistory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            slidingUpPanelLayout.collapsePane();
        }
    });
    collapseMap();

    mapFragment = MapFragment.newInstance();
    FragmentTransaction fragmentTransaction = getActivity().getFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.mapContainer, mapFragment, "map");
    fragmentTransaction.commit();

    setUpMapIfNeeded();

    return rootView;
}

From source file:com.javadog.bluetoothproximitylock.test.BluetoothFragmentTest.java

private Fragment addFragment(Fragment fragment) {
    //Add the BT Fragment to the placeholder activity
    FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
    transaction.add(R.id.placeholder_fragment_layout, fragment, "abc");
    transaction.commitAllowingStateLoss();
    getInstrumentation().waitForIdleSync();

    //Return a reference to the Fragment once it's inflated
    return activity.getFragmentManager().findFragmentByTag("abc");
}