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:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel// ww w .  j  a  va2s. c  om
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.tassadar.multirommgr.MainActivity.java

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

    if (Build.VERSION.SDK_INT == 20) {
        showDeprecatedLAlert();//w ww. j  a  v  a  2 s .c  o  m
        return;
    }

    setContentView(R.layout.activity_main);

    // This activity is using different background color, which would cause overdraw
    // of the whole area, so disable the default background
    getWindow().setBackgroundDrawable(null);

    Utils.installHttpCache(this);
    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    m_srLayout = (MultiROMSwipeRefreshLayout) findViewById(R.id.refresh_layout);
    m_srLayout.setOnRefreshListener(this);

    m_curFragment = -1;

    m_fragmentTitles = getResources().getStringArray(R.array.main_fragment_titles);
    m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    m_drawerList = (ListView) findViewById(R.id.left_drawer);

    String[] fragmentClsNames = new String[MainFragment.MAIN_FRAG_CNT];
    for (int i = 0; i < fragmentClsNames.length; ++i)
        fragmentClsNames[i] = MainFragment.getFragmentClass(i).getName();

    m_fragments = new MainFragment[MainFragment.MAIN_FRAG_CNT];
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction t = fragmentManager.beginTransaction();
    for (int i = 0; i < m_fragments.length; ++i) {
        m_fragments[i] = (MainFragment) fragmentManager.findFragmentByTag(fragmentClsNames[i]);
        if (m_fragments[i] == null) {
            m_fragments[i] = MainFragment.newFragment(i);
            t.add(R.id.content_frame, m_fragments[i], fragmentClsNames[i]);
        }
        t.hide(m_fragments[i]);
    }
    t.commit();

    // Set the adapter for the list view
    m_drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, m_fragmentTitles));
    // Set the list's click listener
    m_drawerList.setOnItemClickListener(new DrawerItemClickListener());

    m_drawerTitle = getText(R.string.app_name);
    m_drawerToggle = new ActionBarDrawerToggle(this, m_drawerLayout, R.string.drawer_open,
            R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(m_title);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(m_drawerTitle);
        }
    };
    m_drawerLayout.setDrawerListener(m_drawerToggle);

    final ActionBar bar = getSupportActionBar();
    if (bar != null) {
        bar.setDisplayHomeAsUpEnabled(true);
        bar.setHomeButtonEnabled(true);
    }

    if (getIntent().hasExtra(INTENT_EXTRA_SHOW_ROM_LIST)
            && getIntent().getBooleanExtra(INTENT_EXTRA_SHOW_ROM_LIST, false)) {
        getIntent().removeExtra(INTENT_EXTRA_SHOW_ROM_LIST);
        selectItem(1);
    } else if (savedInstanceState != null) {
        selectItem(savedInstanceState.getInt("curFragment", 0));
    } else {
        selectItem(0);
    }
}

From source file:com.android.purenexussettings.TinkerActivity.java

private void removeCurrent() {
    // update the main content by replacing fragments, first by removing the old
    FragmentTransaction fragtrans = fragmentManager.beginTransaction();
    fragtrans.setCustomAnimations(R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
    fragtrans.remove(fragmentManager.findFragmentById(R.id.frame_container));
    fragtrans.commit();
}

From source file:com.cloudbees.gasp.activity.TwitterStreamActivity.java

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

    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Use simple FrameLayout for ListFragment
    setContentView(R.layout.gasp_frame_layout);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ListFragment list = new ListFragment();
    ft.add(R.id.fragment_content, list);

    // Use a simple TextView layout for ArrayAdapter constructor
    mAdapter = new ArrayAdapter<String>(this, R.layout.gasp_generic_textview);

    // Map ArrayAdapter to ListFragment
    list.setListAdapter(mAdapter);/*  w  w w . j  a  v a 2  s  . co  m*/

    // RESTResponderFragments call setRetainedInstance(true) in onCreate()
    TwitterResponderFragment responder = (TwitterResponderFragment) fm
            .findFragmentByTag(getString(R.string.twitter_responder));
    if (responder == null) {
        responder = new TwitterResponderFragment();

        ft.add(responder, getString(R.string.twitter_responder));
    }

    ft.commit();
}

From source file:ab.util.AbDialogUtil.java

/**
 * ??Fragment.// w w w  .ja  v a 2  s .co  m
 * 
 * @param context
 *            the context
 */
public static void removeDialog(Context context) {
    try {
        FragmentActivity activity = (FragmentActivity) context;
        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        // 
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
        Fragment prev = activity.getFragmentManager().findFragmentByTag(mDialogTag);
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);
        if (context != null) {
            ft.commit();
        }
    } catch (Exception e) {
        // ?Activity??
        e.printStackTrace();
    }
}

From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java

protected void removeUI() {
    Log.d(TAG, "removeUI()");
    // must get a new transaction each time
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    // set empty view to visible
    mEmptyView.setVisibility(View.VISIBLE);
    // remove all the fragment
    mPermissionsFragment = (PermissionsFragment) getFragmentManager().findFragmentByTag(mPermissionsTag);

    if (mPermissionsFragment != null) {
        transaction.hide(mPermissionsFragment);
        transaction.hide(mAppsFragment);
    }/*ww w . j  av a  2s  . c  o  m*/
    transaction.commit();
    getFragmentManager().executePendingTransactions();
    // remove tabs on actionbar
    mActionBarAdapter.removeAllTab();
}

From source file:com.hufeiya.SignIn.activity.QuizActivity.java

private void inflateFragment() {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (AsyncHttpHelper.user.getUserType()) {//student
        if (category.getId().equals("addcourse")) {

        } else {/*from w  ww. j a  v a 2s .com*/
            courseInfoFragment = CourseInfoFragment.newInstance(category.getName());
            transaction.replace(R.id.content, courseInfoFragment);
        }

    } else {//teacher

    }
    transaction.commit();
}

From source file:com.grepsound.activities.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction./*from w  w  w .  ja  va 2s .  c om*/
 */
private void switchFragments() {
    if (mIsAnimating) {
        Log.i(TAG, "IS animating!");
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        Log.i(TAG, "Did Slide Out!");
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_left, 0, 0,
                        R.animator.slide_fragment_right);
                transaction.add(R.id.move_to_back_container, mDetailsFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                mDidSlideOut = false;
            }
        };
        slideBack(listener);
    }
}

From source file:org.kymjs.kjframe.KJActivity.java

/**
 * Fragment?//from   w w  w. j av a  2s .  co m
 *
 * @param resView        ??
 * @param targetFragment ??Fragment
 */
public void changeFragment(int resView, KJFragment targetFragment) {
    if (targetFragment.equals(currentKJFragment)) {
        return;
    }
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    if (!targetFragment.isAdded()) {
        transaction.add(resView, targetFragment, targetFragment.getClass().getName());
    }
    if (targetFragment.isHidden()) {
        transaction.show(targetFragment);
        targetFragment.onChange();
    }
    if (currentKJFragment != null && currentKJFragment.isVisible()) {
        transaction.hide(currentKJFragment);
    }
    currentKJFragment = targetFragment;
    transaction.commit();
}

From source file:com.example.koppa.driverlicensev2.MainActivity.java

public void addClientFragment() {
    Fragment frag = null;/*from   ww w .j ava 2s  .  co m*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (navigationView == null) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.inflateMenu(R.menu.nav_menu_client);
        toolbar.setVisibility(View.VISIBLE);
    }

    frag = new ClientFragment();

    fragmentTransaction.replace(R.id.fragment_container, frag);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

}