There are several ways to pass the data from one fragment to another, but the simplest ways is the using of bundle.
Bundle is basically use to store the data for t he current session only. it can be transfer one page to another only within that session in which it was created. There are multiple type of data that bundle supports like int, string, Boolean etc.
Bundle store all the values in the form of "Key" & "Values"
FragmentManager fragmentManager = this.FragmentManager;
FragmentTransaction fragmentTransaction = fragmentManager.BeginTransaction();
Fragments.MedicineSearchResultsFragment fragmentS1 = new Fragments.MedicineSearchResultsFragment();
Bundle bundle = new Bundle();
bundle.PutString("MedicineName", "Asomex");
fragmentS1.Arguments = bundle;
fragmentTransaction.Replace(Resource.Id.content_frame, fragmentS1);
fragmentTransaction.AddToBackStack(fragmentS1.Class.SimpleName);
fragmentTransaction.Commit();
Once the values is assigned with bundle it can be transferred to another page. On the second page using Bundle we can get all the values using key.
On the second page initialize the Bundle on the OnCreate method and by using key we can get all the stored values.
static string _medicinekeyword = string.Empty;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Bundle bundle = this.Arguments;
_medicinekeyword = bundle.GetString("MedicineName") ?? "0";
}
Bundle is basically use to store the data for t he current session only. it can be transfer one page to another only within that session in which it was created. There are multiple type of data that bundle supports like int, string, Boolean etc.
Bundle store all the values in the form of "Key" & "Values"
FragmentManager fragmentManager = this.FragmentManager;
FragmentTransaction fragmentTransaction = fragmentManager.BeginTransaction();
Fragments.MedicineSearchResultsFragment fragmentS1 = new Fragments.MedicineSearchResultsFragment();
Bundle bundle = new Bundle();
bundle.PutString("MedicineName", "Asomex");
fragmentS1.Arguments = bundle;
fragmentTransaction.Replace(Resource.Id.content_frame, fragmentS1);
fragmentTransaction.AddToBackStack(fragmentS1.Class.SimpleName);
fragmentTransaction.Commit();
Once the values is assigned with bundle it can be transferred to another page. On the second page using Bundle we can get all the values using key.
On the second page initialize the Bundle on the OnCreate method and by using key we can get all the stored values.
static string _medicinekeyword = string.Empty;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Bundle bundle = this.Arguments;
_medicinekeyword = bundle.GetString("MedicineName") ?? "0";
}
No comments:
Post a Comment