Example usage for android.app FragmentTransaction replace

List of usage examples for android.app FragmentTransaction replace

Introduction

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

Prototype

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

Source Link

Document

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

Usage

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

public void addQuestionListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    QuestionListFragment cuQuestionFragment = new QuestionListFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();/*from   w  w w .  java 2  s  .c  om*/
}

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

public void addUserListFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    AdminStatisticFragment cuQuestionFragment = new AdminStatisticFragment();
    fragmentTransaction.replace(R.id.fragment_container, cuQuestionFragment);
    fragmentTransaction.commit();//  www  .j a  va  2s  .c om
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*  w  w w  . j a  va 2 s . co m*/
public boolean onNavigationItemSelected(MenuItem item) {

    int id = item.getItemId();

    android.app.FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (id == R.id.maintopics_logo) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    } else if (id == R.id.international_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InternationalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.entertainment) {
        fragmentTransaction.replace(R.id.fragment_container, EntertainmentFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.it_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ItFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("IT");
        mToolbar.setTitleMargin(340, 0, 0, 0);

    } else if (id == R.id.local_logo) {
        fragmentTransaction.replace(R.id.fragment_container, LocalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.domestic_logo) {
        fragmentTransaction.replace(R.id.fragment_container, DomesticFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.economy_logo) {
        fragmentTransaction.replace(R.id.fragment_container, EconomyFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.sports_logo) {
        fragmentTransaction.replace(R.id.fragment_container, SportsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.science_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ScienceFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.interestgraph_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if (id == R.id.your_like_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if ("License".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, LicenseFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("License");
        mToolbar.setTitleMargin(280, 0, 0, 0);

    } else if ("?".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:de.sourcestream.movieDB.controller.GalleryList.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *//*w  w  w .j  a va  2  s.  c  om*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    FragmentManager manager = getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle args = new Bundle();
    args.putStringArrayList("galleryList", galleryPath);
    args.putInt("currPos", position);
    galleryPreview.setArguments(args);
    transaction.replace(R.id.frame_container, galleryPreview);
    // add the current transaction to the back stack:
    transaction.addToBackStack("galleryList");
    transaction.commit();

}

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

public void addTestLicenseFragment() {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    TestLicense testLicense = new TestLicense();
    testLicense.setUserModel(userModel);
    fragmentTransaction.replace(R.id.fragment_container, testLicense);
    fragmentTransaction.commit();//from w ww . ja v a 2  s  .  co  m
}

From source file:com.amaze.filemanager.activities.Preferences.java

public void donate() {
    try {/*  w w w.jav a 2  s  .  c  om*/
        getFragmentManager().beginTransaction().remove(p).commit();
    } catch (Exception e) {
        e.printStackTrace();
    }

    String[] s = new String[] { "Minimal Donation", "Medium Donation", "High Donation" };
    DonationsFragment donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, true, GOOGLE_PUBKEY,
            GOOGLE_CATALOG, s, false, null, null, null, false, null, null, false, null);
    android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.prefsfragment, donationsFragment);
    transaction.commit();
    getSupportActionBar().setTitle(R.string.donate);

}

From source file:com.optimusinfo.elasticpath.cortex.common.EPFragmentActivity.java

/**
 * This method adds a fragment to the current activity
 * /*  w  w w. j  a v a2  s.c  o  m*/
 * @param title
 * @param isNew
 * @param tag
 * @param fargmentContainerId
 * @param objFragment
 */
public void addFragmentToBreadCrumb(String title, int fargmentContainerId, EPFragment objFragment) {
    String breadTitle = title;
    if (title.length() > 16) {
        breadTitle = title.substring(0, 14).concat(getString(R.string.ellipsis));
    }
    mStackLevel++;
    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setBreadCrumbTitle(breadTitle);
    ft.replace(fargmentContainerId, objFragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    ft.addToBackStack(null);
    ft.commit();

}

From source file:com.example.sans.myapplication.Login.OnlineActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_online);

    shares = getSharedPreferences("SHARES", 0);

    Fragment newFragment = new OnlineBotFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.login_bot, newFragment);
    transaction.addToBackStack(null);//from  w  ww .j  a  v  a  2s .c  o m
    transaction.commit();

    transaction = getFragmentManager().beginTransaction();
    newFragment = new LoginTopFragment();
    transaction.replace(R.id.login_top, newFragment);
    transaction.commit();

    toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    //Initializing NavigationView
    navigationView = (NavigationView) findViewById(R.id.navigation_view);

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu

    header = navigationView.inflateHeaderView(R.layout.header);
    JSONObject driver_data = null;
    try {
        driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR"));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    TextView driver_name_header = (TextView) header.findViewById(R.id.username);
    TextView car_id_header = (TextView) header.findViewById(R.id.car_id);
    final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image);

    try {
        car_id_header.setText(driver_data.getString("license"));
        driver_name_header.setText(driver_data.getString("name"));
        Client client = new Client();
        client.get(driver_data.getString("image"),
                new FileAsyncHttpResponseHandler(OnlineActivity.this.getApplicationContext()) {
                    @Override
                    public void onFailure(int i, Header[] headers, Throwable throwable, File file) {

                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final File response) {

                        OnlineActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap image = BitmapFactory.decodeFile(response.getPath());

                                pp_header.setImageBitmap(image);

                            }
                        });

                    }

                });
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        SharedPreferences.Editor editor = shares.edit();

        final Client client1 = new Client();
        RequestParams params1 = new RequestParams();

        editor.putBoolean("ONLINE", false);
        editor.putBoolean("LOGIN", false);
        editor.commit();
        Intent intent = getApplicationContext().getPackageManager()
                .getLaunchIntentForPackage(getApplicationContext().getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", 0);
            OnlineActivity.this.startActivity(i);
            drawerLayout.closeDrawers();
        }
    });

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Checking if the item is in checked state or not, if not make it in checked state

            nav = true;

            menuItem.setChecked(false);

            //Closing drawer on item click
            drawerLayout.closeDrawers();

            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment fragment;
            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {
            case R.id.timetable:
            case R.id.service:
            case R.id.history:
            case R.id.mission:
            case R.id.points:
            case R.id.notice:
                Intent i = new Intent(OnlineActivity.this, MenuItemActivity.class);
                i.putExtra("MENU_ITEM", menuItem.getItemId());
                OnlineActivity.this.startActivity(i);
                break;
            case R.id.login:
                Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
                SharedPreferences.Editor editor = shares.edit();

                final Client client = new Client();
                RequestParams params = new RequestParams();
                params.put("id", shares.getInt("ID", 0));
                params.put("status", 999);
                client.post("driver/setStatus", params, new JsonHttpResponseHandler());

                editor.putBoolean("ONLINE", false);
                editor.putBoolean("LOGIN", false);
                editor.commit();
                Intent intent = getApplicationContext().getPackageManager()
                        .getLaunchIntentForPackage(getApplicationContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                break;

            }
            return false;
        }
    });

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
            drawerLayout.setSelected(false);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank

            super.onDrawerOpened(drawerView);
        }
    };

    drawerLayout.setDrawerListener(actionBarDrawerToggle);

    actionBarDrawerToggle.syncState();
}

From source file:com.orpheusdroid.screenrecorder.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w w w . jav  a2s.  com*/

    //Arbitrary "Write to external storage" permission since this permission is most important for the app
    requestPermissionStorage();

    //final boolean isServiceRunning = isServiceRunning(RecorderService.class);
    //Let's add SettingsPreferenceFragment to the activity
    FragmentManager mFragmentManager = getFragmentManager();
    FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
    SettingsPreferenceFragment mPrefsFragment = new SettingsPreferenceFragment();
    mFragmentTransaction.replace(R.id.settingsFragment, mPrefsFragment);
    mFragmentTransaction.commit();

    //Acquiring media projection service to start screen mirroring
    mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    //Respond to app shortcut
    if (getIntent().getAction() != null
            && getIntent().getAction().equals(getString(R.string.app_shortcut_action))) {
        startActivityForResult(mProjectionManager.createScreenCaptureIntent(), SCREEN_RECORD_REQUEST_CODE);
        return;
    }

    fab = (FloatingActionButton) findViewById(R.id.fab);

    if (isServiceRunning(RecorderService.class)) {
        Log.d(Const.TAG, "service is running");
        changeFabIcon(Status.RECORDING);
    }
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mMediaProjection == null && !isServiceRunning(RecorderService.class)) {
                //Request Screen recording permission
                startActivityForResult(mProjectionManager.createScreenCaptureIntent(),
                        SCREEN_RECORD_REQUEST_CODE);
            } else if (isServiceRunning(RecorderService.class)) {
                //stop recording if the service is already active and recording
                Intent stopRecording = new Intent(MainActivity.this, RecorderService.class);
                stopRecording.setAction(Const.SCREEN_RECORDING_STOP);
                startService(stopRecording);
                changeFabIcon(Status.STOPPED);
            }
        }
    });
    fab.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            //Show hint toast based on recording status
            if (isServiceRunning(RecorderService.class))
                Toast.makeText(MainActivity.this, R.string.fab_record_hint, Toast.LENGTH_SHORT).show();
            else
                Toast.makeText(MainActivity.this, R.string.fab_stop_hint, Toast.LENGTH_SHORT).show();
            return true;
        }
    });

}

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

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    switch (id) {
    case R.id.nav_admin_add:
        addCUQuestionFragment();/*from w w w.ja v  a 2  s. co m*/
        break;

    case R.id.nav_admin_edit:
        addQuestionListFragment();
        break;

    case R.id.nav_client_new_test:
        addTestLicenseFragment();
        break;
    case R.id.nav_admin_sign_out:
    case R.id.nav_client_sign_out:
        signout();
        break;
    case R.id.nav_client_statistics:
        addStatisticFragment();
        break;
    case R.id.nav_admin_users:
        addUserListFragment();
        break;
    case R.id.nav_client_practice:
        addPracticeFragment();
        break;

    case R.id.nav_admin_settings:
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        SettingsFragment settingsFragment = new SettingsFragment();
        fragmentTransaction.replace(R.id.fragment_container, settingsFragment);
        fragmentTransaction.commit();
        break;
    default:
        break;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}