我想使用地方自動完成所以我閱讀了谷歌檔案,我使用了“嵌入自動完成支持片段”選項,但我輸入的完全相同,由谷歌撰寫,但有這樣的錯誤
- 類“從 PlaceSelectionListener 派生的匿名類”必須宣告為抽象或在“PlaceSelectionListener”中實作抽象方法“onPlaceSelected(Place)”
- 方法不會覆寫其超類中的方法
我確實覆寫了方法“onPlaceSelected”,但是當我輸入代碼時,代碼變為灰色和在下面的 PlaceSelectionListener 創建的紅線..
我不知道為什么所以請幫忙...
代碼在這里
public class FinalTest extends FragmentActivity {
private static int AUTOCOMPLETE_REQUEST_CODE = 1;
private static final String TAG = "FinalTest";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_test);
Places.initialize(getApplicationContext(), "my_api_key");
PlacesClient placesClient = Places.createClient(this);
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
// Specify the types of place data to return.
autocompleteFragment.setTypeFilter(TypeFilter.ADDRESS);
autocompleteFragment.setLocationBias(RectangularBounds.newInstance(
new LatLng(-33.880490, 151.184363),
new LatLng(-33.858754, 151.229596)));
autocompleteFragment.setCountries("IN");
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID,Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: " place.getName() ", " place.getId());
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " status);
}
});
}
}
uj5u.com熱心網友回復:
你沒有顯示你的進口,但我猜你有這個進口:
匯入 com.google.android.gms.location.places.ui.PlaceSelectionListener;
將其更改為:
匯入 com.google.android.libraries.places.widget.listener.PlaceSelectionListener;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/313501.html
