List of usage examples for android.app Fragment setArguments
public void setArguments(Bundle args)
From source file:tools.ToolsManpowerHomeActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment; Bundle bundle;/*from w ww. java 2s.co m*/ FragmentManager fragmentManager; switch (position) { case 0: fragment = new ToolsManpowerHomeFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 1: fragment = new UpdateManpowerFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 2: fragment = new ToolUpdateFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 3: AlertDialog.Builder bulder = new AlertDialog.Builder(ToolsManpowerHomeActivity.this); bulder.setTitle("Are you sure ?...."); bulder.setIcon(R.drawable.ic_launcher); bulder.setMessage("You want to Logout"); bulder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(ToolsManpowerHomeActivity.this, MainActivity.class); startActivity(intent); } }); bulder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(ToolsManpowerHomeActivity.this, "Welldone", Toast.LENGTH_LONG).show(); dialog.dismiss(); } }); AlertDialog d = bulder.create(); d.show(); break; case 4: break; default: break; } }
From source file:iovi.testtask.MainActivity.java
private void selectItem(int position) { Fragment fragment = new ListF(); FragmentManager fragmentManager;/* ww w.j a va2 s.c o m*/ FragmentTransaction fragmentTransaction; Bundle args = new Bundle(); args.putString("Title", mMenuTitles[position]); switch (position) { case 0: args.putString(ListF.TABLE, DataBaseHelper.TABLE_ORGANISATIONS); args.putString(ListF.COLUMN, DataBaseHelper.NAME); args.putString(ListF.SELECTION, null); args.putStringArray(ListF.ARGS, null); fragment.setArguments(args); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); break; case 1: args.putString(ListF.TABLE, DataBaseHelper.TABLE_NEWS); args.putString(ListF.COLUMN, DataBaseHelper.NEWS_TITLE); args.putString(ListF.SELECTION, null); args.putStringArray(ListF.ARGS, null); fragment.setArguments(args); fragmentManager = getFragmentManager(); fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); break; case 2: fragment = new ContactsF(); fragment.setArguments(args); fragmentManager = getFragmentManager(); fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mMenuTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:cafe.com.navigationdrawer.NavigationDrawerActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment; int viewId;// w w w . j a v a 2s .c o m switch (position) { case 0: viewId = R.layout.fragment_listview; fragment = new HomeFragment(); break; default: viewId = R.layout.activity_scrollview; fragment = new SampleFragment(); } Bundle args = new Bundle(); args.putInt(SampleFragment.ARG_IMAGE_RES, mMenuImages[position]); args.putInt(SampleFragment.ARG_ACTION_BG_RES, R.drawable.ab_background); args.putInt(SampleFragment.ARG_LAYOUT_ID, viewId); fragment.setArguments(args); 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(mMenuNames[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.coderdojo.libretalk.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new BackgroundFragment(); Bundle args = new Bundle(); args.putInt(BackgroundFragment.ARG_BACKGROUND, position); fragment.setArguments(args); 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); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.example.android.shuttershock.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment = new filterFragment(); Bundle args = new Bundle(); args.putInt(filterFragment.ARG_filter_NUMBER, position); fragment.setArguments(args); 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(mfilterTitles[position]);/*w w w . j a v a 2s . c o m*/ mDrawerLayout.closeDrawer(mDrawerList); /* if (position == 0) { readDates(); dataList.setAdapter(adapter); } */ }
From source file:com.example.bhumiputra.FarmerHomeActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment; Bundle bundle;/*from w w w.jav a 2s. com*/ FragmentManager fragmentManager; switch (position) { case 0: fragment = new FarmerFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 1: fragment = new FarmerBuyFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 2: fragment = new FarmerHireFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 3: fragment = new FarmerSaleFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 4: AlertDialog.Builder bulder = new AlertDialog.Builder(FarmerHomeActivity.this); bulder.setTitle("Are you sure ?...."); bulder.setIcon(R.drawable.ic_launcher); bulder.setMessage("You want to Logout"); bulder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(FarmerHomeActivity.this, MainActivity.class); startActivity(intent); } }); bulder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(FarmerHomeActivity.this, "Welldone", Toast.LENGTH_LONG).show(); dialog.dismiss(); } }); AlertDialog d = bulder.create(); d.show(); break; default: break; } /* fragment = new FarmerFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); 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(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 5: */ }
From source file:cn.scujcc.bug.bitcoinplatformandroid.fragment.ActualTransactionFragment.java
@Nullable @Override//www . j a va2 s.c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_tab, container, false); setHasOptionsMenu(true); setTitle(view, ""); SlidingTabLayout slidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.tablayout); ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager); mRecyclerViewBuy = (RecyclerView) view.findViewById(R.id.recyclerViewBuy); mRecyclerViewSell = (RecyclerView) view.findViewById(R.id.recyclerViewSell); mBuyList = new ArrayList<>(); mSellList = new ArrayList<>(); for (int i = 0; i < 6; i++) { Trend trend1 = new Trend(); trend1.setCount(0); trend1.setPrice(0); Trend trend2 = new Trend(); trend2.setCount(0); trend2.setPrice(0); mBuyList.add(trend1); mSellList.add(trend2); } mBuyAdapter = new DataAdapter(mBuyList, false); mSellAdapter = new DataAdapter(mSellList, true); mRecyclerViewBuy.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerViewSell.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerViewBuy.setHasFixedSize(true); mRecyclerViewSell.setHasFixedSize(true); mRecyclerViewBuy.setAdapter(mBuyAdapter); mRecyclerViewSell.setAdapter(mSellAdapter); // ViewPager ArrayList<Fragment> fragments = new ArrayList<Fragment>(); CandlestickChartsFragment candlestickChartsFragment = new CandlestickChartsFragment(); Bundle atChartsBundle = new Bundle(); atChartsBundle.putBoolean(CandlestickChartsFragment.ARGS_IS_FULL, false); candlestickChartsFragment.setArguments(atChartsBundle); fragments.add(candlestickChartsFragment); Fragment buyFragment = new BuyAndSellFragment(); Bundle buyBundle = new Bundle(); buyBundle.putBoolean(BuyAndSellFragment.ARGS_IS_Sell, false); buyFragment.setArguments(buyBundle); Fragment sellFragment = new BuyAndSellFragment(); Bundle SellBundle = new Bundle(); SellBundle.putBoolean(BuyAndSellFragment.ARGS_IS_Sell, true); sellFragment.setArguments(SellBundle); fragments.add(buyFragment); fragments.add(sellFragment); mViewPagerAdapter = new ViewPagerAdapter(getChildFragmentManager(), fragments); viewPager.setOffscreenPageLimit(fragments.size()); viewPager.setAdapter(mViewPagerAdapter); slidingTabLayout.setViewPager(viewPager, calculateScreenX()); return view; }
From source file:org.adictolinux.mfcclone.MainActivity.java
private void replaceFragment(Fragment fragment, int position) { Bundle args = new Bundle(); // Guardamos la instancia de scan o reseteamos estado switch (position) { case 0:/*from ww w. j a va2 s. co m*/ case 1: case 5: scan_fragment = fragment; scan_fragment_type = position; break; default: scan_fragment = null; } args.putString(KeyProfileFragment.ARG_SECTION, getResources().getStringArray(R.array.menu_array)[position]); fragment.setArguments(args); 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(menuTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:org.horizonremote.MainActivity.java
private void showFragment(int type, int data) { Fragment fragment = null; switch (type) { case FRAGMENT_MAIN: fragment = new MainFragment(); break;/*w w w . j a va 2 s . c o m*/ case FRAGMENT_CONTROLLER: fragment = new ControllerFragment(); Bundle args = new Bundle(); ControllerInfo info = ControllerInfo.get(this, data); if (info != null) { setTitle(info.name); args.putInt(ControllerFragment.ARG_CONTROLLER_ID, data); fragment.setArguments(args); mDrawerLayout.closeDrawer(mDrawerContent); } break; } /* show fragment */ if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); } }
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 . j a v a 2s.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()); }