Example usage for android.app FragmentTransaction commit

List of usage examples for android.app FragmentTransaction commit

Introduction

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

Prototype

public abstract int commit();

Source Link

Document

Schedules a commit of this transaction.

Usage

From source file:com.android.messaging.ui.appsettings.ApplicationSettingsActivity.java

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

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final boolean topLevel = getIntent().getBooleanExtra(UIIntents.UI_INTENT_EXTRA_TOP_LEVEL_SETTINGS, false);
    if (topLevel) {
        getSupportActionBar().setTitle(getString(R.string.settings_activity_title));
    }/*www. j  a  va  2s  .c o  m*/

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(android.R.id.content, new ApplicationSettingsFragment());
    ft.commit();
}

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 ww  . j ava  2s .  com
    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.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:/*w  w  w  . jav a 2s.c o m*/
        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.masil.android.navigationdrawer.NavigationDrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    int id = item.getItemId();
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        if (id == R.id.btn_home) {

            MasilFragment fragment = new MasilFragment();
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.replace(R.id.content_frame, fragment);
            ft.commit();
            return true;

        }/*from  w  w  w.j a va 2s. c o m*/

    }

    return super.onOptionsItemSelected(item);

}

From source file:com.tapchatapp.android.app.activity.MainActivity.java

@Override
public void loadFragments() {
    setContentView(R.layout.activity_main);
    MainFragment fragment = (MainFragment) getFragmentManager().findFragmentByTag("main");
    if (fragment == null) {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.content, new MainFragment(), "main");
        transaction.commit();
    }//from  w w w .  j  a  va  2s.c om
}

From source file:com.tapchatapp.android.app.activity.MainActivity.java

public void showBuffer(int type, long connectionId, long bufferId, boolean isArchived) {
    boolean isTablet = (findViewById(R.id.content1) != null);

    if (isTablet) {
        Fragment fragment = BufferFragment.create(type, connectionId, bufferId);
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.replace(R.id.content1, fragment, "buffer");
        transaction.commit();
    } else {/*  w  w  w  .ja  v a2s. c  om*/
        Intent intent = new Intent(this, BuffersActivity.class);
        Uri data = Uri.parse(String.format("tapchat://%s/%s", connectionId, bufferId));
        if (isArchived) {
            data = data.buildUpon().appendQueryParameter("display", "archived").build();
        }
        intent.setData(data);
        startActivity(intent);
    }
}

From source file:com.pickr.activities.FlickrActivity.java

/**
 * Show a fragment in the main view//from   www . j  av  a  2s. c  om
 * 
 * @param item The fragment to display
 */
private void showFragment(Item<FlickrFragment> item) {
    FlickrFragment fragment = item.getValue();
    FragmentManager fragmentManager = getFragmentManager();

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.flickrFragmentsLayout, fragment, fragment.getClass().getSimpleName());
    transaction.commit();

    getActionBar().setTitle(fragment.getTitle());

    mCurrentFragment = fragment;
    for (Item<FlickrFragment> item2 : mDrawerListItems) {
        item2.setSelected(false);
    }
    item.setSelected(true);
    mDrawerListAdapter.notifyDataSetChanged();
}

From source file:com.ariesmcrae.eskwela.celebtweet.MainActivity.java

/** Add Friends Fragment to Activity */
private void addFriendsFragment() {
    mFriendsFragment = new FriendsFragment();
    mFriendsFragment.setArguments(getIntent().getExtras());

    FragmentTransaction transaction = mFragmentManager.beginTransaction();
    transaction.add(R.id.fragment_container, mFriendsFragment);

    transaction.commit();
}

From source file:com.Candy.ota.CandyOTA.java

private void addShortCutFragment() {
    FragmentManager fragmentManager = this.getActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    CandyLinks candyLinks = new CandyLinks();
    fragmentTransaction.replace(R.id.linksFragment, candyLinks);
    fragmentTransaction.commit();
}

From source file:com.slim.ota.SlimOTA.java

private void addShortCutFragment() {
    FragmentManager fragmentManager = this.getActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    SlimLinks slimLinks = new SlimLinks();
    fragmentTransaction.replace(R.id.linksFragment, slimLinks);
    fragmentTransaction.commit();
}