Reputation: 117
I am new developer of Android.How we can share the data between two fragment. Any idea for this problem.i have make the orderFragment and itemfragment user select the item on item screen and press submit the screen redirct to orders screen user have multiple order.if we redirect the screen the data not send to the orders screen
Upvotes: 0
Views: 53
Reputation: 170
For Send data between two fragment try below code
YourSubmitButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Bundle bundle = new Bundle();
bundle.putString = ("KEY",value) //Here if you want to send Integer value then write putInt
YourItemFragment.setArguments(bundle);
}
}
In ItemFragment try below code
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_order, container, false);
String YourItem = getArguments.getString("KEY");
return view;
}
Upvotes: 1
Reputation: 2727
Its simple to send data between fragments try this
Bundle bundle = new Bundle();
bundle.putString("YourKeyHere",value);
itemFragment.setArguments(bundle);
And then in order Fragment
receive as
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String item = getArguments().getString("YourKeyHere");
return inflater.inflate(R.layout.fragment, container, false);
}
Upvotes: 1