0

I used Google Places AutocompleteFragment for loading address from user. The selected address from the dropdown list working fine inside Activity. But when i use fragment instead of Activity, its not working.

3
  • You need to be more clear with your query! What was working with activity but not with fragment? You mean with the activity you were able to receive the onPlaceSelected callback? Also add more helpful tags to your question like "google-places-api","mapfragment" etc to attract more attention. Commented Jan 5, 2016 at 7:20
  • I am able to get address from activity, but when i use fragment autocomplete callback not working Commented Jan 5, 2016 at 10:16
  • Pls share the code depicting how you are using PlaceAutocompleteFragment inside your fragment (including the xml) Commented Jan 6, 2016 at 8:47

1 Answer 1

1

According to Google Places API for Android, if your fragment is nested within another fragment, your app must also forward onActivityResult() calls from the containing fragment to work around a known limitation of android.support.v4.app.Fragment. This is 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); } 
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried this approach but it appears that onActivityResult is not being called. Logcat shows "E/Places: Unknown PlaceAutocompleteAdapter state change."
Callbacks were not working because my PlaceSelectedListener was not initialized due to incorrect retrieval of my fragment (fragment was null). mAutocompleteFragment = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); was the correct way to retrieve the fragment in my case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.