0

I have two fragments... First is sender fragment(name is DashBoardFragment), code is...

 Bundle args= new Bundle();
 args.putInt("position", i+1);
 new CheckOutFragment().setArguments(args);
 fragmentTransaction = getFragmentManager().beginTransaction();
 fragmentTransaction.replace(R.id.mainframe_container, new CheckOutFragment());
 fragmentTransaction.commit();

And reciever fragment's(CheckOutFragment) code is...

    Bundle bundle = this.getArguments();
    position = bundle.getInt("position");
    Log.d("Got Position", String.valueOf(position));

Problem is i am not getting the value from getArguments(). Guys do help me out...

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443

1 Answers1

1

You're using two different instances of CheckOutFragment and the second one (the one you use with your FragmentTransaction) is not the one you've called setArguments() on.

Instead, use a local variable:

CheckOutFragment fragment = new CheckOutFragment();
fragment.setArguments(args);
fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.mainframe_container, fragment);
fragmentTransaction.commit();
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443