List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.castoffline.mediaactivity.MainActivity.java
private void displayView(int position) { Fragment fragment = null;//w ww. j a v a 2 s . co m switch (position) { case 0: fragment = new VideoPlayerActivity(); break; case 1: fragment = new ImageGrid(); break; case 2: fragment = new AudioPlayerActivity(); break; default: break; } if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } else { Log.e("MainActivity", "Error in creating fragment"); } }
From source file:com.example.t_danbubbletea.MySelections.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_tea_selections, container, false); getActivity().setTitle("Tea Selections"); // animation when enter home page rootView.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.image_click)); //download the URL's asynchronously (put the info in the teaInfo object) try {// w w w.j ava 2 s . c o m teaInfo = new GetTeaInfoTask().execute(new ApiConnector()).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } //make the gridview, set its adapter GridView gridView = (GridView) rootView.findViewById(R.id.grid_view_tea_selections); GridViewCustomAdapter gvAdapter = new GridViewCustomAdapter(getActivity(), teaInfo.imageURLs, teaInfo.teaNames); gridView.setAdapter(gvAdapter); //make the on click listeners gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Fragment newFragment; switch (position) { default: Bundle teaViewArgs = new Bundle(); teaViewArgs.putString("teaName", teaInfo.teaNames.get(position)); teaViewArgs.putString("teaImgUrl", teaInfo.imageURLs.get(position)); teaViewArgs.putString("teaDesc", teaInfo.teaDescriptions.get(position)); newFragment = new TeaViewFragment(); newFragment.setArguments(teaViewArgs); break; } if (newFragment != null) { flipCard(newFragment); } } private void flipCard(Fragment newFragment) { mShowingBack = true; FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .setCustomAnimations(R.anim.card_flip_right_in, R.anim.card_flip_right_out, R.anim.card_flip_left_in, R.anim.card_flip_left_out) .replace(R.id.frame_container, newFragment).addToBackStack(null).commit(); // create new fragment and allow user to go back to previous fragment } }); return rootView; }
From source file:org.meruvian.midas.core.drawer.NavigationDrawer.java
public void replaceFragment(Fragment fragment, String tag) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.content_frame, fragment, tag).addToBackStack(null).commit(); }
From source file:com.albertcbraun.wifidlitedemoapp.MainActivity.java
@Override public void onNavigationDrawerItemSelected(int position) { Log.v(TAG, "onNavigationDrawerItemSelection. position:" + position); // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); switch (position) { case 0:/* w w w . j a va 2 s. co m*/ ft.replace(R.id.container, PeerListAcquisition.newInstance(position)); break; case 1: ft.replace(R.id.container, PeerListSubscription.newInstance(position)); break; case 2: ft.replace(R.id.container, Misc.newInstance(position)); break; } ft.commit(); }
From source file:it.mobistego.MainActivity.java
@Override public void onDelete() { FragmentManager ft = getFragmentManager(); FragmentTransaction tx = ft.beginTransaction(); MainFragment mainF = new MainFragment(); tx.replace(R.id.listFragment, mainF, Constants.CONTAINER); tx.commit();//from ww w .j a v a2s . c om }
From source file:models.newArrivalFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_newarrival, container, false); getActivity().setTitle("New Arrivals!"); //animation when enter home page rootView.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.image_click)); //download the URL's asynchronously (put the info in the teaInfo object) try {/* w w w .ja va 2 s .c om*/ teaInfo = new GetTeaInfoTask().execute(new ApiConnector()).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } //make the gridview and set its adapter GridView gridView = (GridView) rootView.findViewById(R.id.grid_view_new_arrival); GridViewCustomAdapter gvAdapter = new GridViewCustomAdapter(getActivity(), teaInfo.imageURLs, teaInfo.teaNames); gridView.setAdapter(gvAdapter); //onclick listener for gridview gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Bundle teaViewArgs = new Bundle(); teaViewArgs.putString("teaName", teaInfo.teaNames.get(position)); teaViewArgs.putString("teaImgUrl", teaInfo.imageURLs.get(position)); teaViewArgs.putString("teaDesc", teaInfo.teaDescriptions.get(position)); Fragment newFragment = new TeaViewFragment(); newFragment.setArguments(teaViewArgs); if (newFragment != null) { flipCard(newFragment); } } private void flipCard(Fragment newFragment) { mShowingBack = true; FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .setCustomAnimations(R.anim.card_flip_right_in, R.anim.card_flip_right_out, R.anim.card_flip_left_in, R.anim.card_flip_left_out) .replace(R.id.frame_container, newFragment).addToBackStack(null).commit(); // create new fragment and allow user to go back to previous fragment } }); return rootView; }
From source file:it.mobistego.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_fragment); init();//from ww w .j av a2 s. com FragmentManager ft = getFragmentManager(); FragmentTransaction tx = ft.beginTransaction(); MainFragment mainF = new MainFragment(); tx.replace(R.id.listFragment, mainF, Constants.CONTAINER); tx.commit(); }
From source file:it.ncorti.emgvisualizer.ui.MainActivity.java
/** * Private method for triggering a fragment switch at runtime * @param fragment Fragment involved/*from w w w. j ava 2s . c o m*/ * @param position Position of the menu to be selected */ private void changeFragment(Fragment fragment, int position) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.main_content_frame, fragment).commit(); // Highlight the selected item, update the title, and close the drawer setTitle(TITLES[position - 1]); mAdapter.updateSelectedItem(position); mDrawerLayout.closeDrawers(); }
From source file:com.arquitetaweb.ttinder.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new PlanetFragment(); Bundle args = new Bundle(); args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args);//from www. ja v a2 s . c om FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.desitum.landscape_connect.activities.HomeActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new HomeActivityFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerLayout.closeDrawer(mDrawerList); }