2

Hello I'm trying to pass a String value from a fragment to another one. I have a single Activity.

The thing that I'm trying to do is when a listview item is pressed send the value to the another fragment, load the fragment (This I had made with this code):

Fragment cambiarFragment = new FragmentInterurbanos();
                Bundle args = new Bundle();
FragmentTransaction transaction = getFragmentManager().beginTransaction();


                transaction
                        .replace(R.id.container, cambiarFragment)
                        .addToBackStack(null)
                        .setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);

                // Commit the transaction
                transaction.commit();

And then retrieve the String and update a WebView placed in the new fragment (This method cannot be launched when the user select in NavigationDrawer this section (Fragment).

Thanks for your help in advance!

makgyverzx
  • 39
  • 6
  • if you are sending String from fragment to fragment then try [Communicating Fragments](http://developer.android.com/training/basics/fragments/communicating.html) – Spurdow Aug 20 '14 at 16:15

1 Answers1

2

There are many ways you can achieve this... you could pass the string to the new Fragment through a Bundle like this:

Bundle bundle = new Bundle();
bundle.putString(key, value);
fragment.setArguments(bundle);

or maybe have a DataController class where you store the string and the new fragment retrieves it.

Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53