0

How can we send data from actvity to fragment? The Fragments are configured to actvity by using FragmentPagerAdapter.

Regards mini.

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
mini
  • 855
  • 4
  • 15
  • 22

2 Answers2

1
  • You can pass a bundle to the fragment on creation with setArguments.
  • You can create methods to set the data on the Fragment class.
Veeti
  • 5,270
  • 3
  • 31
  • 37
0

You can perform this by using Bundle

Send data from the activity (or fragment) :

int a = 5;

Bundle args = new Bundle(); 
args.putInt("INT_DATA_TAG", a); 

Fragment fragment = Fragment.newInstance(args); 
//Making fragment transaction 

Retrieve data in the fragment

int a;
public static Fragment newInstance(Bundle args) {
      a = args.getInt("INT_DATA_TAG"); //use a constant for the tag
      return new Fragment();
}
Sofiane Hassaini
  • 315
  • 3
  • 12