My application has and activity with a viewPager and 4 fragments.
In one fragment I added a google SupportPlaceAutocompleteFragment and 
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.area_swipe_fragment, container, false);
    SupportPlaceAutocompleteFragment autocompleteFragment = (SupportPlaceAutocompleteFragment)
            getChildFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            Toast.makeText(ctx, "do something", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onError(Status status) {
        }
    });
    return view;
}
My problem is the onPlaceSelectedListener is never fired and I can't get the result of the selected place. Instead get fired the onActivityResults() placed in the second fragment.
I tried with a onActivityResults() in the first fragment but it doesn't get fired, always executed the one in the second fragment.
Any ideas?
From the docs:
If your fragment is nested within another fragment, your app must also forward onActivityResult() calls to the containing fragment, as shown in the following snippet:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    autocompleteFragment.onActivityResult(requestCode, resultCode, data);
}
Perhaps this is the solution.
The @AndrewR answer took me on the right track, very similar to the comments, I override onActivityResult however it didn't work.
The problem was the host Activity wasn't calling the super:
public class HostActivity extends AppCompatActivity {
    //Please don't forget other relevant methods
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //super.onActivityResult... is the important line
        //Add other custom behaviours
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With