0

my goal is to transport fragment data to another fragment.

this is what in have:

String ProductNummer_VALUE = NummerName.getText().toString();

         Intent modify_intent = new Intent(getActivity(), MyActivity.class);

       modify_intent.putExtra("memberName", ProductNummer_VALUE);




            Log.i("MyActivity", "ListHistoryFragment " + ProductNummer_VALUE);
            ((MyActivity)getActivity()).test();

MyActivity:

public void test(){

        // Create new fragment and transaction
        Fragment newFragment = new DisplayFragment();
        FragmentTransaction fragmentManager = getSupportFragmentManager().beginTransaction();
        fragmentManager.replace(R.id.container, newFragment).addToBackStack(null).commit();

    }

i tried using several methods, but i cant seem to get a handle on it.

Data is not being transported, because i tried using intents, to transport the data, but this way i couldnt launch to the new fragment. It just stayed on the MyActivity.class

  • http://stackoverflow.com/questions/16036572/how-to-pass-values-between-fragments – Naveen Tamrakar Nov 21 '14 at 13:31
  • i Found that yesterday, and all it seems to do is pass the value, and afterwards launch my activity. So the MyActivity.class is called twice, stacked. – Randadin Nov 21 '14 at 13:41

1 Answers1

0

try this,

YourNewFragment ldf = new YourNewFragment ();
Bundle args = new Bundle();
args.putString("YourKey", "YourValue");
ldf.setArguments(args);
getFragmentManager().beginTransaction().add(R.id.container, ldf).commit();

In onCreateView of the new Fragment:

String value = getArguments().getString("YourKey");