Adding a package to a fragment from a fragment

I have the following lines in my code

FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_content, fragment, fargmentTag);

Now I want to add the package to my fragment. How can i do this?

+5
source share
3 answers

Try the following:

Inside your FragmentActivity class, put this:

MyFragmentClass mFrag = new MyFragmentClass();
Bundle bundle = new Bundle();
bundle.putString("DocNum", docNum);   //parameters are (key, value).
mFrag.setArguments(bundle);

getSupportFragmentManager().beginTransaction().replace(R.id.page_fragments, mFrag).commit();

Im using "import android.support.v4.app.FragmentActivity;" so I use "getSupportFragmentManager ()". So, to summarize the above code, u created an instance of the package and an instance of your fragment. Then you linked the two objects with "mFrag.setArguments (bundle)". So now the “package” is associated with this instance of your MyFragmentClass. Therefore, anywhere in your MyFragmentClass, download the package by calling:

Bundle bundle = getArguments();
String mDocNum = bundle.getString("DocNum");
+6
source

ft.replace(R.id.fragment_content, fragment, fargmentTag); :

fragment.setArguments(bundle).

+4

replace fragment.setArguments(bundle)

0

All Articles