我正在尝试在一个片段中实现Google Places自动完成适配器。我从一个Google Places示例应用程序获取了适配器的代码。这是来自该类的自动完成适配器类placeautocompleteadpter cunstructor
public PlaceAutocompleteAdapter(Context context, GeoDataClient geoDataClient,
LatLngBounds bounds, AutocompleteFilter filter) {
super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1);
mGeoDataClient = geoDataClient;
mBounds = bounds;
mPlaceFilter = filter;
}
问题是当我尝试在片段中实现它时。该演示在一个活动中实现,并且它用于geodataclient的参数是“ this”,最初我只是放置MyFragment.this.getActivity(),因为这是我用于上下文参数的内容。但是我意识到这是在要求geodataclient,我不确定如何解决这个问题,因为这是我的第一个Android应用程序。这是我片段中的相关部分:
//TODO fix autocoplete adapter
mGoogleApiClient = new GoogleApiClient
.Builder(NewFragment.this.getActivity())
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.enableAutoManage(NewFragment.this.getActivity(), this)
.build();
//getting error when using "this" for second argument
mPlaceAutoCompleteAdapter = new PlaceAutocompleteAdapter(NewFragment.this.getActivity(), this,
LAT_LNG_BOUNDS, null);
locOne.setAdapter(mPlaceAutoCompleteAdapter);
locTwo.setAdapter(mPlaceAutoCompleteAdapter);
//TODO end
感谢您的帮助!