List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:am.hour.beebird.Activity.MainActivity.java
public void selectItem(int position, int info) { // update the main content by replacing fragments //??????/*from w w w.j a v a 2 s.com*/ if (position == recent_fragment_number) { mDrawerLayout.closeDrawer(mDrawerLeftLayout); return; } if (position == 0) { setTitle(R.string.list_left_zero); if (fragments.get(position) == null) { SharedPreferences sharedpreference = getSharedPreferences("unknown", MODE_PRIVATE); int loginornot = sharedpreference.getInt("LOGINORNOT", 0); if (loginornot == 0) fragment = new LoginFragment(); else if (loginornot == 1) fragment = new PersonalFragment(); } else { fragment = fragments.get(position); } recent_fragment_number = 0; } if (position == 1) { ll_random.setBackgroundResource(R.color.ll_leftdrawer_checked); ll_liked.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); ll_setting.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); setTitle(R.string.list_left_one); if (fragments.get(position) == null) { fragment = new JobFragment(); } else { fragment = fragments.get(position); } recent_fragment_number = 1; } if (position == 2) { ll_random.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); ll_liked.setBackgroundResource(R.color.ll_leftdrawer_checked); ll_setting.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); setTitle(R.string.list_left_two); if (fragments.get(position) == null) { fragment = new LikedFragment(); } else { fragment = fragments.get(position); } recent_fragment_number = 2; } if (position == 3) { ll_random.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); ll_liked.setBackgroundResource(R.color.ll_leftdrawer_nonchecked); ll_setting.setBackgroundResource(R.color.ll_leftdrawer_checked); setTitle(R.string.list_left_three); if (fragments.get(position) == null) { fragment = new SettingFragment(); } else { fragment = fragments.get(position); } recent_fragment_number = 3; } Bundle args = new Bundle(); args.putInt(Constant.ARG_FRAGMENT_INFO, info); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerLayout.closeDrawer(mDrawerLeftLayout); }
From source file:org.openlmis.core.view.activity.BaseActivity.java
private void initDataFragment() { FragmentManager fm = getFragmentManager(); dataFragment = (RetainedFragment) fm.findFragmentByTag("RetainedFragment"); if (dataFragment == null) { dataFragment = new RetainedFragment(); fm.beginTransaction().add(dataFragment, "RetainedFragment").commit(); }/*from w w w. j a v a 2s .c o m*/ }
From source file:me.isassist.isa.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar mToolbar = (Toolbar) findViewById(R.id.list_row_name); setSupportActionBar(mToolbar);/* w w w. ja v a 2 s .co m*/ DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); } mLocationRequest = createLocationRequest(); //restoring activity (restart) if (savedInstanceState != null) { mLastLocation = savedInstanceState.getParcelable("LOCATION"); mListType = (Bihapi) savedInstanceState.getSerializable("LIST_TYPE"); //we need to launch a previous fragment if (mListType != null) { Fragment fragment = new ListFragment(); Bundle args = new Bundle(); if (mLastLocation == null) { Toast.makeText(this, "Waiting for the location...", Toast.LENGTH_LONG).show(); } else { args.putSerializable("API_TYPE", mListType); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit(); } } } else { boolean allFilesExist = true; for (Bihapi b : Bihapi.values()) { if (fileExists(b)) { } else { allFilesExist = false; } } if (allFilesExist) { showMainFragment(); } else { showLoadingFragment("Loading data\n Please wait!"); for (Bihapi b : Bihapi.values()) { if (!fileExists(b)) { new FetchAPI(this, this, b, FetchAPI.FetchType.FILE_RESOURCES).execute(); } } } } Log.i(TAG, "SCIEZKA: " + getFilesDir().getAbsolutePath()); }
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 w w .jav 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:org.vqeg.viqet.activities.MainActivity.java
private void selectItem(int position) { Fragment fragment = null;//www . ja va2 s . c o m // update the main content by replacing fragments switch (position) { case 0: fragment = new HomeFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment, "Home Fragment").commit(); break; case 1: fragment = new ResultsListFragment(); FragmentManager fragmentManager1 = getFragmentManager(); fragmentManager1.beginTransaction().replace(R.id.content_frame, fragment, "Results List Fragment") .commit(); break; case 2: fragment = new SingleResultsListFragment(); FragmentManager fragmentManager5 = getFragmentManager(); fragmentManager5.beginTransaction() .replace(R.id.content_frame, fragment, "Results Single List Fragment").commit(); break; case 3: fragment = new HelpFragment(); FragmentManager fragmentManager2 = getFragmentManager(); fragmentManager2.beginTransaction().replace(R.id.content_frame, fragment, "Help Fragment").commit(); break; case 4: fragment = new AboutFragment(); FragmentManager fragmentManager3 = getFragmentManager(); fragmentManager3.beginTransaction().replace(R.id.content_frame, fragment, "About Fragment").commit(); break; case 5: fragment = new SettingsFragment(); FragmentManager fragmentManager4 = getFragmentManager(); fragmentManager4.beginTransaction().replace(R.id.content_frame, fragment, "Settings Fragment").commit(); break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mOptionsTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:heartware.com.heartware_master.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDBAdapter = new DBAdapter(this); // adding invisible worker fragments: https://developer.android.com/guide/components/fragments.html mJboneHelper = new JawboneUpHelper(); FragmentManager fm = getFragmentManager(); fm.beginTransaction().add(mJboneHelper, JawboneUpHelper.TAG).commit(); mLoginDialog = new LoginDialogFragment(); mLoginDialog.show(getFragmentManager(), TAG); setupActionTabs();/*from w ww . j a va2s . co m*/ //get user calendar availability avail = checkEvents(); Toast.makeText(this, "Available: " + avail, Toast.LENGTH_LONG).show(); //send user availability to server //CalToServer calToServer = (CalToServer) new CalToServer().execute(new String(avail)); }
From source file:blackman.matt.infinitebrowser.InfinityBrowser.java
/** * Creates a new board for a post when reply button is hit. * * @param boardRoot Link to the thread to open up * @param threadNo Thread no being opened *///w ww . j a v a2 s . c o m @Override public void onReplyClicked(String boardRoot, String threadNo) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); Boolean ageAccept = preferences.getBoolean("age_guard_accept", false); if (ageAccept) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); LinearLayout helpText = (LinearLayout) findViewById(R.id.ll_help_add_boards); Board newThread = Board.newInstance(boardRoot, threadNo); fragmentTransaction.replace(R.id.container, newThread, threadNo); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); helpText.setVisibility(View.GONE); mTitle = boardRoot.replace("https://8chan.co", "") + threadNo; setTitle(mTitle); } }
From source file:cz.zcu.kiv.eeg.mobile.base.ui.NavigationActivity.java
public boolean openSection(int itemPosition) { Intent intent;//from w w w . j a v a 2 s . c om if (itemPosition != previousFragment) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); switch (itemPosition) { // dashboard case 0: DashboardFragment dashboardFrag; dashboardFrag = new DashboardFragment(); fragmentTransaction.replace(R.id.content, dashboardFrag, DashboardFragment.TAG); fragmentTransaction.commit(); previousFragment = itemPosition; break; // scenarios case 1: intent = new Intent(); intent.setClass(this, ScenarioActivity.class); startActivity(intent); break; // experiments case 2: intent = new Intent(); intent.setClass(this, ExperimentActivity.class); startActivity(intent); break; // datafile upload case 3: DataFileUploadFragment dataFileFrag; dataFileFrag = new DataFileUploadFragment(); fragmentTransaction.replace(R.id.content, dataFileFrag, DataFileUploadFragment.TAG); fragmentTransaction.commit(); previousFragment = itemPosition; break; // reservations case 4: ReservationFragment agendaFrag; agendaFrag = new ReservationFragment(); fragmentTransaction.replace(R.id.content, agendaFrag, ReservationFragment.TAG); fragmentTransaction.commit(); previousFragment = itemPosition; break; // application settings case 5: intent = new Intent(); intent.setClass(this, SettingsActivity.class); startActivity(intent); break; default: return false; } } drawerLayout.closeDrawer(drawerList); return true; }
From source file:jsettlers.main.android.JsettlersActivity.java
public void showFragment(JsettlersFragment fragment) { FragmentManager manager = getFragmentManager(); if (!fragment.shouldAddToBackStack()) { manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); }//from ww w . ja v a 2s .c o m FragmentTransaction transaction = manager.beginTransaction(); if (fragment.shouldAddToBackStack()) { transaction.addToBackStack(fragment.getName()); } transaction.replace(R.id.base_menu, fragment); transaction.commit(); }
From source file:com.scto.android.calma.activities.CalmaActivity.java
/** * Diplaying fragment view for selected nav drawer list item * *///from w w w . j a v a2s . c o m private void displayView(int position) { // update the main content by replacing fragments Fragment fragment = null; switch (position) { case 0: fragment = new HomeFragment(); break; case 1: fragment = new FindPeopleFragment(); break; case 2: fragment = new PhotosFragment(); break; case 3: fragment = new CommunityFragment(); break; case 4: fragment = new PagesFragment(); break; case 5: fragment = new WhatsHotFragment(); break; default: break; } if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } else { // error in creating fragment Log.e("MainActivity", "Error in creating fragment"); } }