I know there are duplicate questions for this. But their problem is between Activity
and Fragment
. My problem is about passing a value from Adapter
to Fragment
.
I Toast the value from adapter and it shows the correct value. I used the putString
and setArguments
methods but it returns null.
Here is what I did in my Adapter:
Bundle cart_bundle = new Bundle();
cart_bundle.putString("total", String.valueOf(total_amount));
Cart_Fragment fragment = new Cart_Fragment();
fragment.setArguments(cart_bundle);
((User_Activity)context).getSupportFragmentManager().beginTransaction()
.commit();
Here is how I receive the argument in Fragment :
Bundle cart_bundle = this.getArguments();
tv_total_amount.setText("Total Amount: "+ cart_bundle.getString("total"));
Maybe there is something wrong in ((User_Activity)context).getSupportFragmentManager().beginTransaction()
.commit();
There is an error if I try to replace the User_Activity to Fragment.
P.S.
I don't need to use replace()
method because the adapter is an adapter for the list view in the fragment.