Android – the onplaceselectedlistener of supportplaceautocompletefragment is not triggered inside the viewpager
•
Android
My application has an activity with viewpager and four fragments. In one fragment, I added a Google supportplace autocompletefragment 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 one rror(Status status) {
}
});
return view;
}
My problem is that onplaceselectedlistener will never be triggered, and the results of the selected location cannot be obtained. Instead, onactivityresults() in the second fragment will be triggered. I try to use onactivityresults() in the first fragment, but it will not be triggered. Please always execute in the second fragment
Any ideas?
resolvent:
Start with the docs:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
autocompleteFragment.onActivityResult(requestCode, resultCode, data);
}
Maybe that's the solution
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码