Example usage for android.app FragmentManager beginTransaction

List of usage examples for android.app FragmentManager beginTransaction

Introduction

In this page you can find the example usage for android.app FragmentManager beginTransaction.

Prototype

public abstract FragmentTransaction beginTransaction();

Source Link

Document

Start a series of edit operations on the Fragments associated with this FragmentManager.

Usage

From source file:com.masil.android.navigationdrawer.NavigationDrawerActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    //  Fragment fragment = PlanetFragment.newInstance(position);

    switch (position) {
    case 0://  ww w .j  ava 2 s  .  com
        MasilFragment fragment = new MasilFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.replace(R.id.content_frame, fragment);
        ft.commit();
        break;
    case 1:
        Toast.makeText(getApplicationContext(), "? ", Toast.LENGTH_SHORT).show();
        break;
    case 2:
        Toast.makeText(getApplicationContext(), "? ?", Toast.LENGTH_SHORT).show();
        break;
    case 3:
        Toast.makeText(getApplicationContext(), "? ?", Toast.LENGTH_SHORT).show();
        break;

    }

    // update selected item title, then close the drawer
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.dooweb.flip.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Log.v("selectItem position", Integer.toString(position));
    Fragment fragment = null;//from w ww .  j  a  v  a  2s  .  co m
    if (position == 0) {
        if (currentDashboard != null)
            fragment = currentDashboard;
        else
            fragment = new Dashboard();
        currentDashboard = (Dashboard) fragment;
    } else if (position == 1) {
        fragment = new Profile();
    } else if (position == 2) {
        fragment = new Settings();
    } else if (position == 3) {
        fragment = new TestNotification();
    } else if (position == 4) {
        Login.disconnect();
        Intent new_intent = new Intent(MyApplication.getAppContext(), Starter.class);
        startActivity(new_intent);
        finish();
        return;
    } else {
        fragment = new PlanetFragment();
        Bundle args = new Bundle();
        args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
        fragment.setArguments(args);
    }
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.athena.broncobattle.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments

    Log.i("selectItem", "New item selected: " + position);

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // Sets an ID for the notification, so it can be updated
    int notifyID = 1;
    Builder mNotifyBuilder = new NotificationCompat.Builder(this).setContentTitle("New Message")
            .setContentText("You've received new messages.").setSmallIcon(android.R.drawable.ic_menu_compass);

    mNotifyBuilder.setContentText("Some text!").setNumber(++numMessages);
    // Because the ID remains unchanged, the existing notification is
    // updated.//from   w w  w. jav a 2 s . c  o m
    mNotificationManager.notify(notifyID, mNotifyBuilder.build());

    if (!(position < 0)) {
        if (fragments[position] == null) {
            switch (position) {
            case 0:
                fragments[position] = new QuestionsFragment();
                break;
            case 1:
                fragments[position] = new LeaderboardFragment();
                break;
            case 2:
                fragments[position] = new StatsFragment();
                break;
            }
        }

        // Fragment fragment = new PlanetFragment();
        // Bundle args = new Bundle();
        // args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
        // fragment.setArguments(args);

        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragments[position]).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position + 1, true);
        setTitle(mDrawerButtonTitles[position]);
        // setTitle(mPlanetTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }
}

From source file:com.jackie.navigationDrawer.MainActivity.java

/**
 * Swaps fragments in the main content view
 * @param position list position/*from w w w. ja  v  a  2s. c o  m*/
 */
private void selectItem(int position) {
    // Create a new fragment and specify the planet to show based on position
    Fragment fragment = new PlaneFragment();
    Bundle args = new Bundle();
    args.putInt(PlaneFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);

    // Insert the fragment by replacing any existing existing fragment
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

    // Highlight the selected item update the title, and close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

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

private void _replaceRightFragment(Fragment fragment, String tag) {
    FragmentManager manager = getFragmentManager();
    Fragment replacement = manager.findFragmentByTag(tag);

    if (replacement == null) {
        replacement = fragment;//from   ww w.  j ava2  s .c o m
    }

    FragmentTransaction transaction = manager.beginTransaction();
    transaction.replace(R.id.right_fragment, replacement, tag);
    transaction.commit();

    _drawer.closeDrawers();
}

From source file:com.dono.psakkos.dono.MainActivity.java

private void showLonelyFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    LonelyFragment lonelyFragment = new LonelyFragment();
    fragmentTransaction.replace(R.id.mainFragment, lonelyFragment);
    fragmentTransaction.commit();/*from  www .java  2s. co  m*/
}

From source file:com.dono.psakkos.dono.MainActivity.java

private void showLabelsFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    LabelsFragment labelsFragment = new LabelsFragment();
    fragmentTransaction.replace(R.id.mainFragment, labelsFragment);
    fragmentTransaction.commit();//  ww  w  . j  a  v  a  2  s.  com
}

From source file:com.dono.psakkos.dono.MainActivity.java

private void showAddLabelFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    AddLabelFragment addlabelFragment = new AddLabelFragment();
    fragmentTransaction.replace(R.id.mainFragment, addlabelFragment);
    fragmentTransaction.commit();/*from w  ww  .  j  a va2 s .c  o m*/
}

From source file:com.dono.psakkos.dono.MainActivity.java

private void showKeyFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    KeyFragment keyFragment = new KeyFragment();
    fragmentTransaction.replace(R.id.mainFragment, keyFragment);

    fragmentTransaction.commit();/*from www  .  j  a va 2  s  . co m*/
}

From source file:de.azapps.mirakel.new_ui.activities.MirakelActivity.java

private void setList(final ListMirakel listMirakel) {
    final FragmentManager fragmentManager = getFragmentManager();
    final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    final TasksFragment tasksFragment = getTasksFragment();
    tasksFragment.setList(listMirakel);/*from ww w  .  j ava2 s.  c  om*/
    fragmentTransaction.commit();
}