From the official documentaion :
setArguments
Added in API level 11 void setArguments (Bundle args) Supply the
construction arguments for this fragment. This can only be called
before the fragment has been attached to its activity; that is, you
should call it immediately after constructing the fragment. The
arguments supplied here will be retained across fragment destroy and
creation.
You can't call Fragment.setArguments()
once the fragment is attached to its activity.
Do something like this instead:
Bundle arg = new Bundle();
arg.putInt("productId", idToRead);
Fragment fragCurrent = context.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
FragmentTransaction fragTransaction = context.getSupportFragmentManager().beginTransaction();
fragTransaction.detach(fragCurrent);
FragmentProductList fragment = new FragmentProductList();
fragment.setArguments(arg);
fragTransaction.attach(fragment);
fragTransaction.commit();
Note that : Here you are creating a new instance of your fragment and then attaching it. You can't change the arguments of the same instance of fragment once you've set them.
Or if you want to put new values to the same fragment then you can use getArguments()
. Something like this :
Fragment fragCurrent = context.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
Bundle arg = fragCurrent.getArguments();
arg.putInt("productId", idToRead);
FragmentTransaction fragTransaction = context.getSupportFragmentManager().beginTransaction();
fragTransaction.detach(fragCurrent);
fragTransaction.attach(fragCurrent);
fragTransaction.commit();