Example usage for android.support.v4.app FragmentTransaction replace

List of usage examples for android.support.v4.app FragmentTransaction replace

Introduction

In this page you can find the example usage for android.support.v4.app FragmentTransaction replace.

Prototype

public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);

Source Link

Document

Calls #replace(int,Fragment,String) with a null tag.

Usage

From source file:ch.citux.td.ui.fragments.ChannelFragment.java

private void setFragment(Fragment fragment, boolean backstack) {
    if (fragment != null) {
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        if (fragmentManager != null) {
            FragmentTransaction transaction = fragmentManager.beginTransaction();

            if (backstack) {
                transaction.addToBackStack(null);
            }//  w  w  w.ja v  a  2s.  c  om

            Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
            if (currentFragment == null) {
                transaction.add(R.id.container, fragment);
            } else {
                if (!currentFragment.equals(fragment)) {
                    transaction.replace(R.id.container, fragment);
                } else {
                    ((TDBase) fragment).loadData();
                }
            }
            transaction.commit();
        }
    }
}

From source file:com.bydavy.card.receipts.activities.ReceiptListActivity.java

private void replaceListFragment(String selection, String[] selectionArgs, String sortOrder) {
    showLoadingAndSHideContent();//from  w  w  w .  j a  v a  2s.  c  o m

    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

    mReceiptListFragment = ReceiptListFragment.newInstance(selection, selectionArgs, sortOrder);
    mReceiptListFragment.setStateListener(mReceiptListFragmentListener, true);

    ft.replace(FRAGMENT_RECEIPT_LIST_ID, mReceiptListFragment);

    if (mDualPane) {
        mPagerFragment = ReceiptPagerFragment.newInstance(selection, selectionArgs, sortOrder);
        mPagerFragment.setStateListener(mPagerFragmentListener, true);
        ft.replace(FRAGMENT_PAGER_FRAGMENT_ID, mPagerFragment);
    }

    ft.commit();
}

From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePageFragment.java

@Nullable
@Override/*ww  w  . j a va2 s.  co  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.schedule_page, container, false);
    Bundle arguments = getArguments();

    FragmentManager fragmentManager = getChildFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    Func2<Integer, Integer, ?> setRecord = (dayOfWeek, layoutId) -> {
        String key = ARG_DAY + dayOfWeek;
        ScheduleRecord record = arguments.getParcelable(key);

        if (record != null) {
            Fragment fragment = (record.course != null) ? new RecordFragment() : new EmptyRecordFragment();
            Bundle args = new Bundle();
            args.putParcelable(RecordFragment.ARG_RECORD, record);
            fragment.setArguments(args);
            fragmentTransaction.replace(layoutId, fragment);
        }

        return 0;
    };

    setRecord.call(Calendar.MONDAY, R.id.layoutMonday);
    setRecord.call(Calendar.TUESDAY, R.id.layoutTuesday);
    setRecord.call(Calendar.WEDNESDAY, R.id.layoutWednesday);
    setRecord.call(Calendar.THURSDAY, R.id.layoutThursday);
    setRecord.call(Calendar.FRIDAY, R.id.layoutFriday);
    setRecord.call(Calendar.SATURDAY, R.id.layoutSaturday);
    setRecord.call(Calendar.SUNDAY, R.id.layoutSunday);

    fragmentTransaction.commit();
    return rootView;
}

From source file:com.cnm.cnmrc.fragment.vodtvch.VodTvchBase.java

private void loadingData() {
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    Class<?> classObject;/*from   w  ww .j  a  va  2 s.c om*/
    try {
        classObject = Class.forName(packageName + mClassTypeArray[selectedCategory]);
        Object obj = classObject.newInstance();

        Base base = ((Base) obj).newInstance(mCategoryArray[selectedCategory]);

        //ft.addToBackStack(null);
        ft.replace(R.id.loading_data_panel, base);
        ft.commit();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (java.lang.InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate View StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *//*from  w w  w.j  av  a  2  s . co  m*/
public void openViewStoryFragment(long index) {
    Log.d(LOG_TAG, "openStoryViewFragment(" + index + ")");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != StoryViewFragment.class) {
            StoryViewFragment details = StoryViewFragment.newInstance(index);

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.
            ft.replace(R.id.details, details);

        } else {
            // Check what fragment is shown, replace if needed.
            StoryViewFragment details = (StoryViewFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (details == null || details.getUniqueKey() != index) {
                // Make new fragment to show this selection.
                details = StoryViewFragment.newInstance(index);

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newStoryViewIntent(this, index);
        startActivity(intent);
    }
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate Edit StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *//*from  w  w  w .ja  va 2  s. c o  m*/
public void openEditStoryFragment(final long index) {
    Log.d(LOG_TAG, "openEditStoryFragment(" + index + ")");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != EditStoryFragment.class) {
            EditStoryFragment editor = EditStoryFragment.newInstance(index);

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, editor);

        } else {
            // Check what fragment is shown, replace if needed.
            EditStoryFragment editor = (EditStoryFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (editor == null || editor.getUniqueKey() != index) {
                // Make new fragment to show this selection.
                editor = EditStoryFragment.newInstance(index);

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, editor);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newEditStoryIntent(this, index);
        startActivity(intent);
    }
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    int pos = tab.getPosition();
    controlling = pos == 0;// w  w w.  j  ava 2 s.  c  o m
    ft.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
    currentFragment = tabFragments[pos];
    ft.replace(android.R.id.content, currentFragment);
}

From source file:com.ariesmcrae.mymemories.ui.story.StoryActivityBase.java

/**
 * Logic required to open the appropriate Create StoryData Fragment/Activity
 * combination to display properly on the phone or tablet.
 *///from www  .j a v a 2  s .c  o  m
public void openCreateStoryFragment() {
    Log.d(LOG_TAG, "openCreateStoryFragment");
    if (determineDualPane()) {

        Fragment test = getSupportFragmentManager().findFragmentById(R.id.details);

        // Log.d(LOG_TAG, "open view class:" + test.getClass());
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        if (test != null && test.getClass() != CreateStoryFragment.class) {
            CreateStoryFragment details = CreateStoryFragment.newInstance();

            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        } else {
            // Check what fragment is shown, replace if needed.
            CreateStoryFragment details = (CreateStoryFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.details);
            if (details == null) {
                // Make new fragment to show this selection.
                details = CreateStoryFragment.newInstance();

            }
            // Execute a transaction, replacing any existing
            // fragment with this one inside the frame.

            ft.replace(R.id.details, details);

        }
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.commit();

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = newCreateStoryIntent(this);
        startActivity(intent);
    }
}

From source file:com.cosmicsubspace.nerdyaudio.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final Thread.UncaughtExceptionHandler orig = Thread.getDefaultUncaughtExceptionHandler();
    final Context c = getApplicationContext();
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override//w w w.  j  a  v a 2 s  .c  om
        public void uncaughtException(Thread thread, Throwable e) {
            Log2.log(0, this, "UncaughtException logged:", Log2.logToString(e));
            //Toast.makeText(c, ErrorLogger.logToString(e), Toast.LENGTH_SHORT).show();
            FileWriter f;
            try {
                f = new FileWriter(new File(Environment.getExternalStorageDirectory() + "/AFN_exceptions.txt"),
                        true);
                f.write("\n\n\n" + DateFormat.getDateTimeInstance().format(new Date()) + "\n");
                f.write(Log2.logToString(e));
                f.flush();
                f.close();
            } catch (IOException e1) {
                Log2.log(e1);
            } //Double exception?

            Log2.dumpLogsAsync();

            orig.uncaughtException(thread, e);
        }
    });

    requestPermission();

    Log2.log(1, this, "MainActivity Created!");

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    sf = getPreferences(Context.MODE_PRIVATE);

    String[] files = fileList();
    for (String i : files) {
        Log2.log(1, this, "File: " + i);
    }

    qm = QueueManager.getInstance();
    ap = AudioPlayer.getInstance();
    vb = VisualizationBuffer.getInstance();
    fm = FileManager.getInstance();
    wf = Waveform.getInstance();
    sbs = SidebarSettings.instantiate(getApplicationContext());
    vm = VisualizationManager.getInstance();

    volCtrl = new VolumeControls(getApplicationContext(), qm);

    //ap.setBufferFeedListener(vb);

    qm.passContext(getApplicationContext());
    fm.loadFromFile(this);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Library"));
    tabLayout.addTab(tabLayout.newTab().setText("Queue"));
    tabLayout.addTab(tabLayout.newTab().setText("Filters"));
    tabLayout.addTab(tabLayout.newTab().setText("Now Playing"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            int pos = tab.getPosition();
            if (pos == 0)
                ft.replace(R.id.tab_area, new LibraryFragment());
            else if (pos == 1)
                ft.replace(R.id.tab_area, new QueueFragment());
            else if (pos == 2)
                ft.replace(R.id.tab_area, new FiltersFragment());
            else if (pos == 3)
                ft.replace(R.id.tab_area, new NowPlayingFragment());

            ft.commit();
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });
    getSupportFragmentManager().beginTransaction().replace(R.id.tab_area, new LibraryFragment()).commit();

    wfv = (PlayControlsView) findViewById(R.id.waveform);
    wfv.setSpacing(0);
    wfv.setTimestampVisibility(true);
    wfv.setTimestampSize(16);
    wfv.setTimestampColor(Color.WHITE);

    wfv.setTimestampOffset(30, 10);
    wfv.setTimestampBackgroundColor(Color.argb(128, 0, 0, 0));

    wfv.setWaveform(wf);
    qm.addQueueListener(wfv);
    qm.addProgressStringListener(wfv);

    vv = (VisualizationView) findViewById(R.id.visualization);

    dl = (DrawerLayout) findViewById(R.id.drawer_layout);

    dl.setDrawerListener(this);

    settingBtn = (RelativeLayout) findViewById(R.id.settings_btn);
    settingBtn.setOnClickListener(this);

    //statusText=(TextView)findViewById(R.id.status);

    sideContainer = (ScrollView) findViewById(R.id.drawer_scroll);
    sideContainer.addView(sbs.getView(getLayoutInflater(), sideContainer, null));

}

From source file:com.android.transmart.PlaceActivity.java

/**
 * Updates (or displays) the venue detail Fragment when a venue is selected
 * (normally by clicking a place on the Place List.
 * @param reference Place Reference// w  w  w .ja  v a  2s . co m
 * @param id Place Identifier
 */
public void selectDetail(String reference, String id) {
    // If the layout includes a single "main fragment container" then
    // we want to hide the List Fragment and display the Detail Fragment.
    // A back-button click should reverse this operation.
    // This is the phone-portrait mode.
    if (findViewById(R.id.main_fragment_container) != null) {
        placeDetailFragment = PlaceDetailFragment.newInstance(reference, id);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.addToBackStack(null);
        if (checkinFragment != null)
            ft.hide(checkinFragment);
        ft.hide(placeListFragment);
        ft.replace(R.id.main_fragment_container, placeDetailFragment);
        ft.show(placeDetailFragment);
        ft.commit();
        // Otherwise the Detail Fragment is already visible and we can
        // Simply replace the previous Fragment with a new one for the
        // selected Place.
    } else {
        placeDetailFragment = PlaceDetailFragment.newInstance(reference, id);
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.disallowAddToBackStack();
        ft.replace(R.id.detail_fragment_container, placeDetailFragment);
        ft.commit();
    }
}