Reputation: 1385
I have a DialogFragment where I can choose from the list some value. The problem is when I choose a value from the list I don't know how to pass that value to my main fragment.
Any ideas?
Upvotes: 0
Views: 45
Reputation: 1031
You should not try to pass data directly from one fragment to another. You need to pass the data back to the Activity using a callback method. Then the Activity can lookup the other Fragment by id and call a method on it directly to send it the data. There is a tutorial here.
Upvotes: 0
Reputation: 149
Define a method in main fragment
and call it from DialogFramgment
.
While setting values in list,call it as :
((MainActivity)getActivity).setValue(value_set);
And in MainActivity :
public void setValue(String value) {
// Get the value
value_selected_in_list = value;
}
Upvotes: 1