Example usage for android.app Fragment setArguments

List of usage examples for android.app Fragment setArguments

Introduction

In this page you can find the example usage for android.app Fragment setArguments.

Prototype

public void setArguments(Bundle args) 

Source Link

Document

Supply the construction arguments for this fragment.

Usage

From source file:br.com.android.cotuca.toptask.Activitys.MSimplesActivity.java

private void selectItem(int posicao) {

    FragmentManager fm = getFragmentManager();

    if (posicao == 0) {
        Fragment f_tarefas = new FragmentTarefas();
        if (idProjetoSelecionado != 0) {
            Bundle dadosProjeto = new Bundle();
            dadosProjeto.putInt(ContratoProjetos.Colunas._ID, idProjetoSelecionado);

            f_tarefas.setArguments(dadosProjeto);
        }//from   w  ww  .j  a va 2 s.co  m
        fm.beginTransaction().replace(R.id.content_frame, f_tarefas).commit();

    } else if (posicao == 1) {

        if (!dao.getTarefasDoUsuarioNoProjetos(idProjetoSelecionado, idUsuarioSelecionado).isEmpty()) {

            Intent i = new Intent(this, GraficosActivity.class);
            Bundle dados = new Bundle();
            dados.putInt(Tags.ID_PROJETO, idProjetoSelecionado);
            dados.putInt(Tags.ID_USUARIO, idUsuarioSelecionado);
            i.putExtras(dados);
            startActivity(i);
        } else {
            Log.i("lista de tarefas vazia", "lista de tarefas vazia");
            Toast.makeText(getApplicationContext(), "Voce ainda nao possui tarefas", Toast.LENGTH_SHORT).show();
        }
    } else if (posicao == 2) {
        Intent iSairProjetoAtual = new Intent(this, ProjetosActivity.class);
        Bundle dados = new Bundle();
        dados.putInt(Tags.ID_USUARIO, idUsuarioSelecionado);
        iSairProjetoAtual.putExtras(dados);
        iSairProjetoAtual.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(iSairProjetoAtual);
    }
    mDrawerList.setItemChecked(posicao, true);
    setTitle(mPaginaTitulo[posicao]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:se.liu.tddd77.bilsensor.SensorDetailActivity.java

/**
 * Automatically create layout based on XML-files. 
 * The activity is just a shell for the fragment, run on smaller screens. 
 *//*from  w ww .  j a  v a 2s. com*/
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sensor_detail);

    System.out.println("SensorDetailActivity - onCreate: ");
    if (savedInstanceState == null) {
        // Get the detail fragment and add it to the activity
        // using a fragment transaction.
        Bundle arguments = new Bundle();
        Fragment fragment = null;
        try {
            fragment = ElementList.getInstance()
                    .getElement(getIntent().getIntExtra(SensorDetailFragment.ARG_ITEM_ID, 0)).getFragment();
        } catch (IndexOutOfBoundsException e) {
            Log.d("SensorDetailActivity", "List out of bounds");
        }
        if (fragment == null) {
            Log.d("SensorDetailActivity", "fragment == null");
            fragment = new SensorDetailFragment();
        }
        fragment.setArguments(arguments);
        getFragmentManager().beginTransaction().add(R.id.sensor_detail_container, fragment).commit();
    } else {

    }
}

From source file:com.mobile.syslogng.monitor.MainActivity.java

public void setFragment(Fragment fragment, Integer position, String tag) {

    updateDrawer(position);/*from   w w  w. j av a  2 s. c  om*/
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Bundle args = new Bundle();
    args.putInt(MainActivity.FRAGMENT_POS, position);
    fragment.setArguments(args);
    String cTag = "empty";
    Fragment currentFragment = fragmentManager.findFragmentById(R.id.container);
    if (currentFragment != null) {
        cTag = currentFragment.getTag();
        if (!cTag.equals(tag)) {
            if (currentFragment instanceof WelcomeFragment
                    || currentFragment instanceof MonitoredSyslogngFragment
                    || currentFragment instanceof AboutFragment) {
                stackCount = 0;
                transaction.addToBackStack(cTag);
                stackCount++;
            } else {
                if (stackCount < 2) {
                    transaction.addToBackStack(cTag);
                    stackCount++;
                }
            }
        }
    }
    transaction.replace(R.id.container, fragment, tag).commit();
}

From source file:com.google.android.apps.forscience.whistlepunk.devicemanager.ManageDevicesActivity.java

private void setFragment() {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Fragment fragment;
    if (adapter.isEnabled() && ScanDisabledFragment.hasScanPermission(this)) {
        mManageFragment = new ManageDevicesFragment();
        fragment = mManageFragment;/*w  w w. ja  v  a2 s. c o m*/
    } else {
        fragment = new ScanDisabledFragment();
        mManageFragment = null;
    }
    Bundle args = new Bundle();
    args.putString(EXTRA_EXPERIMENT_ID, getIntent().getStringExtra(EXTRA_EXPERIMENT_ID));
    fragment.setArguments(args);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.fragment, fragment);
    ft.commitAllowingStateLoss();
}

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. ja  v  a2 s  .com
        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:io.radio.streamer.MainActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new MenuFragment();
    Bundle args = new Bundle();
    args.putString(MenuFragment.ARG_PAGE_ID, mDrawerMenu[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(mDrawerMenu[position]);/* w w w  . ja v  a 2 s  .c om*/
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:vendor.VendorHomeActivity.java

private void selectItem(int position) {
    // update the main content by replacing fragments

    Fragment fragment;
    Bundle bundle;/*from  w ww  . j ava2  s  . c o  m*/

    FragmentManager fragmentManager;
    switch (position) {

    case 0:

        fragment = new VendorHomeFragmet();
        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 VendorBuyFragmet();
        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 VendorSellFragmet();
        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(VendorHomeActivity.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(VendorHomeActivity.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(VendorHomeActivity.this, "Welldone", Toast.LENGTH_LONG).show();
                dialog.dismiss();
            }
        });

        AlertDialog d = bulder.create();
        d.show();

        break;
    default:
        break;
    }
}

From source file:com.example.android.adrenaland.MainActivity.java

public void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new FragmentHome();
    switch (position) {
    case 0://  www .  ja v a 2 s . c o  m
        fragment = new FragmentHome();
        break;
    case 1:
        fragment = new FragmentNavigation();
        Bundle args = new Bundle();
        args.putBoolean(FragmentNavigation.ARG_CLOUD, false);
        args.putBoolean(FragmentNavigation.ARG_BIG_DROP, false);
        fragment.setArguments(args);
        break;
    case 2:
        fragment = new FragmentWaitTimes();
        break;
    case 3:
        fragment = new FragmentShowTimes();
        break;
    case 4:
        fragment = new FragmentRideInfo();
        break;
    case 5:
        fragment = new FragmentRollerCoasters();
        break;
    }
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    ft.replace(R.id.content_frame, fragment).commit();

    // update selected item and title, then close the drawer
    if (position <= 4) {
        mDrawerList.setItemChecked(position, true);
    }
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.cdhxqh.inventorymovement.ui.MainActivity.java

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
    mSelectPos = position;//from w w  w  .  j  av  a2 s  . co  m

    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    switch (position) {
    case 0://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newItemFragment == null) {
            newItemFragment = new ItemFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newItemFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newItemFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 1://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newPoFragemnt == null) {
            newPoFragemnt = new PoFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newPoFragemnt.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newPoFragemnt).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 2://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newWorkorderFragment == null) {
            newWorkorderFragment = new WorkorderFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newWorkorderFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newWorkorderFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 3://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newCheckFragment == null) {
            newCheckFragment = new CheckFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newCheckFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newCheckFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 4://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newPoFragemnt == null) {
            newLocationFragment = new LocationFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newLocationFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newLocationFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    //            case 5://???
    //                titleTextView.setText(adapter.getTitle(position));
    //                searchButton.setVisibility(View.GONE);
    //                if (newTypoFragment == null) {
    //                    newTypoFragment = new TypoFragment();
    //                    Bundle bundle = new Bundle();
    //                    bundle.putString("text", adapter.getTitle(position));
    //                    newTypoFragment.setArguments(bundle);
    //                }
    //                fragmentTransaction.replace(R.id.content_frame, newTypoFragment).commit();
    //                drawer.closeDrawer(mDrawerList);
    //                break;
    case 5://
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newInVFragment == null) {
            newInVFragment = new InVFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newInVFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newInVFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;
    case 6://?
        titleTextView.setText(adapter.getTitle(position));
        searchButton.setVisibility(View.VISIBLE);
        if (newItemreqFragment == null) {
            newItemreqFragment = new ItemreqFragment();
            Bundle bundle = new Bundle();
            bundle.putString("text", adapter.getTitle(position));
            newItemreqFragment.setArguments(bundle);
        }
        fragmentTransaction.replace(R.id.content_frame, newItemreqFragment).commit();
        drawer.closeDrawer(mDrawerList);
        break;

    case 7: //
        showAlertDialog();
        searchButton.setVisibility(View.GONE);
        drawer.closeDrawer(mDrawerList);
        break;
    default:
        titleTextView.setText(adapter.getTitle(position));
        Fragment contentFragment = new ContentFragment();
        Bundle args = new Bundle();
        args.putString("text", adapter.getTitle(position));
        contentFragment.setArguments(args);

        fragmentTransaction.replace(R.id.content_frame, contentFragment).commit();

        drawer.closeDrawer(mDrawerList);
        break;
    }

}

From source file:com.inde.shiningdays.MainActivity.java

private void selectItem(int position, String orderBy) {
    // update the main content by replacing fragments
    //Fragment fragment = new PlanetFragment();
    //       Intent intent = this.getIntent();
    //       Bundle extras = intent.getExtras();
    //       if(extras != null) {
    //          currentType = extras.getString(CountDown.PRIORITY);
    //       } else {
    //          currentType = mTypes[position];
    //       }//w ww.jav a 2  s  .  com
    if (position == mTypes.length) {
        return;
    }

    currentTypePosition = position;
    currentType = mTypes[position];
    Fragment fragment = new ItemListFragment();
    Bundle args = new Bundle();
    args.putString(CountDown.PRIORITY, currentType);
    args.putString(CountDown.ORDER_BY, orderBy);
    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);
    StringBuilder title = new StringBuilder();
    title.append(getResources().getString(R.string.app_name)).append(".").append(currentType);
    setTitle(title.toString());
    mDrawerLayout.closeDrawer(mDrawerLeft);
}