java - Can PlaceAutocompleteFragment (overlay mode) be called from inside the Fragment class -


i'm working on project create activity(extends appcompatactivity) navigation drawer switching between multiple fragments , 1 of them mapfragment(extends fragment) mapview implementation. i call autocomplete widget, provided google, inside mapfragment class.

here code inside class mapfragment

    placeautocompletefragment autocompletefragment = (placeautocompletefragment)             getfragmentmanager().findfragmentbyid(r.id.place_autocomplete_fragment);      autocompletefilter typefilter = new autocompletefilter.builder()             .settypefilter(autocompletefilter.type_filter_address)             .build();     autocompletefragment.setfilter(typefilter);      autocompletefragment.setonplaceselectedlistener(new placeselectionlistener() {         @override         public void onplaceselected(place place) {             // todo: info selected place.             string placedetailsstr = place.getname() + "\n"                     + place.getid() + "\n"                     + place.getlatlng().tostring() + "\n"                     + place.getaddress() + "\n"                     + place.getattributions();             log.i("onplaceselected", placedetailsstr);             map.movecamera(cameraupdatefactory.newlatlngzoom(place.getlatlng(), 15));          }          @override         public void onerror(status status) {             // todo: handle error.             log.i("onplaceselected", "an error occurred: " + status);         }     }); 

syntax error @

placeautocompletefragment autocompletefragment = (placeautocompletefragment) getfragmentmanager().findfragmentbyid(r.id.place_autocomplete_fragment);

said that

inconvertible type; cannot cast 'android.support.v4.app.fragment' 'com.google.android.gms.location.places.ui.placeautocompletefragment'

but when put set of code inside mainactivity, works fine. so i'm wondering if there's way call autocomplete widget inside fragment it's can't.

any answer appreciated. :)

use getactivity()

    placeautocompletefragment autocompletefragment = (placeautocompletefragment) getactivity().getfragmentmanager().findfragmentbyid(r.id.place_autocomplete_fragment); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -