Example usage for android.app Fragment getTag

List of usage examples for android.app Fragment getTag

Introduction

In this page you can find the example usage for android.app Fragment getTag.

Prototype

final public String getTag() 

Source Link

Document

Get the tag name of the fragment, if specified.

Usage

From source file:com.nathanson.meterreader.activity.MainActivity.java

public void onSectionAttached(Fragment fragment) {
    int number = Integer.valueOf(fragment.getTag());

    switch (number) {
    case SETTINGS_POSITION:
        mTitle = getString(R.string.title_settings);
        break;/*from   ww  w.j a v a2  s.c  o  m*/
    case GRAPH_POSITION:
        mTitle = getString(R.string.title_graph);
        break;

    case STATS_POSITION:
        mTitle = getString(R.string.title_stats);
        break;

    default:
        // do nothing.
    }
}

From source file:org.openmrs.mobile.activities.formdisplay.FormDisplayActivity.java

private int getFragmentNumber(Fragment fragment) {
    String fragmentTag = fragment.getTag();
    String[] parts = fragmentTag.split(":");
    return Integer.parseInt(parts[3]);
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

private void popBackFragment(String removalFragmentTag) {

    Fragment currentFragment = getFragmentManager().findFragmentById(R.id.container);

    if (currentFragment.getTag().equals(getFragmentManager()
            .getBackStackEntryAt(getFragmentManager().getBackStackEntryCount() - 1).getName())) {
        getFragmentManager().popBackStack();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.remove(currentFragment).commit();
        getFragmentManager().executePendingTransactions();
    }//from   w w  w.  j  a  v a  2  s. c o  m
    getFragmentManager().popBackStack();
    Fragment removalFragment = getFragmentManager().findFragmentByTag(removalFragmentTag);
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.remove(removalFragment).commit();
    getFragmentManager().executePendingTransactions();
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

public void setFragment(Fragment fragment, Integer position, String tag) {

    updateDrawer(position);/*from   ww  w  . ja  v a  2s  .c om*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Bundle args = new Bundle();
    args.putInt(MainActivity.FRAGMENT_POS, position);
    fragment.setArguments(args);
    String cTag = "empty";
    Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        cTag = currentFragment.getTag();
        if (!cTag.equals(tag)) {
            if (currentFragment instanceof WelcomeFragment
                    || currentFragment instanceof MonitoredSyslogngFragment
                    || currentFragment instanceof AboutFragment) {
                stackCount = 0;
                transaction.addToBackStack(cTag);
                stackCount++;
            } else {
                if (stackCount < 2) {
                    transaction.addToBackStack(cTag);
                    stackCount++;
                }
            }
        }
    }
    transaction.replace(R.id.container, fragment, tag).commit();
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

private String checkFragment() {
    String currentFragment = null;
    Fragment importFragment = getFragmentManager().findFragmentByTag("fragment_importcert_tag");
    Fragment addSyslogngFragment = getFragmentManager().findFragmentByTag("fragment_addsyslogng_tag");
    if ((importFragment != null && importFragment.isVisible())) {
        currentFragment = importFragment.getTag();
    } else if (addSyslogngFragment != null && addSyslogngFragment.isVisible()) {
        currentFragment = addSyslogngFragment.getTag();
    }/*w w  w. j ava2  s  .c  o m*/
    return currentFragment;
}

From source file:org.servDroid.ui.activity.MainActivityTwoPanes.java

private synchronized void setRighFragment(android.app.Fragment fragment) {
    android.app.FragmentManager fManager = getFragmentManager();
    if (fragment == null && mCurrentFragmentTag != null) {
        fManager.beginTransaction().remove(fManager.findFragmentByTag(mCurrentFragmentTag)).commit();
        mCurrentFragmentTag = null;/* ww w . j av a2 s .  c o  m*/
        return;
    }
    if (mCurrentFragmentTag != null && mCurrentFragmentTag.equals(fragment.getTag())) {
        return;
    }
    if (fragment != null) {
        setRightSuportFragment(null);
    }
    if (mCurrentFragmentTag != null) {
        fManager.beginTransaction().remove(fManager.findFragmentByTag(mCurrentFragmentTag)).commit();
    } else if (fragment == null) {
        mCurrentFragmentTag = null;
        return;
    }
    fManager.beginTransaction().add(R.id.fillableFrameLayout, fragment, fragment.getClass().getSimpleName())
            .commit();
    mCurrentFragmentTag = fragment.getClass().getSimpleName();
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

/**
 * @return index of fragment currently showing
 *//*from   w  w  w .ja va2s  .com*/
int getCurrentFragmentIndex() {
    Fragment fragment = getFragmentManager().findFragmentById(R.id.container);
    if (fragment != null) {
        String positionString = fragment.getTag();
        if (positionString != null) {
            try {
                return Integer.parseInt(positionString);
            } catch (NumberFormatException e) {
                return -1;
            }
        }
    }
    return -1;
}

From source file:com.tapchatapp.android.app.ui.TapchatFragmentStatePagerAdapter.java

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment) object;

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }// w  w w .  j a v a2s. c o  m
    if (DEBUG)
        Log.v(TAG, "Removing item #" + position + ": f=" + object + " v=" + ((Fragment) object).getView());

    while (mSavedState.size() <= position) {
        mSavedState.add(null);
    }
    mSavedState.set(position, mFragmentManager.saveFragmentInstanceState(fragment));

    if (position != getItemPosition(fragment)) {

    }

    // FIXME: This is a disaster.
    Fragment fragmentReal = mFragments.get(position);
    if (fragmentReal != null && fragmentReal != fragment) {
        if (DEBUG)
            Log.w(TAG, "MISMATCHED FRAGMENT!!!! " + position + " " + fragment.getTag() + " "
                    + fragmentReal.getTag() + " " + mFragments.indexOf(fragmentReal));
        fragment = fragmentReal;
    }
    while (mFragments.size() <= position) {
        mFragments.add(null);
    }
    mFragments.set(position, null);

    mCurTransaction.remove(fragment);
}

From source file:de.jadehs.jadehsnavigator.MainActivity.java

private void displayView(int position) {
    // show fragment
    Fragment fragment = null;
    String fragmentTag = "";
    switch (position) {
    case 0://from   www . j a v a  2s  .  c  o m
        fragment = new NewsFragment();
        fragmentTag = navMenuTitles[1];
        break;
    case 1:
        fragment = new InfoSysFragment();
        fragmentTag = navMenuTitles[2];
        break;
    case 2:
        fragment = new VorlesungsplanFragment();
        fragmentTag = navMenuTitles[3];
        break;
    case 3:
        fragment = new MensaplanFragment();
        fragmentTag = navMenuTitles[4];
        break;
    case 4:
        fragment = new MapFragment();
        fragmentTag = navMenuTitles[5];
        break;
    case 5:
        fragment = new AboutFragment();
        fragmentTag = navMenuTitles[6];
        break;
    case 6:
        Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
        startActivity(intent);
        break;
    default:
        break;
    }
    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frame_container, fragment, fragmentTag)
                .addToBackStack(fragment.getTag()).commit();
        mDrawerLayout.closeDrawer(mDrawerList);
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
    } else {
        Log.e(TAG, "Error while creating fragment");
    }
}