2016-06-27 53 views
3

我想使谷歌搜索地方自動完成導航抽屜活動。在工具欄的地方我想顯示搜索自動完成喜歡谷歌地圖應用程序,這裏是截圖顯示我需要什麼。請給我回復... enter image description here在工具欄上的地方自動完成搜索

+0

看到'搜索查看#setSuggestionsAdapter(的CursorAdapter適配器)' – pskink

+0

請給我清楚的答覆。我有搜索,但我需要像上面的搜索屏幕.. –

+0

如果你使用FrameLayout會更好。 –

回答

-1

您需要使用Google Place Services中的片段。 這裏有例如利用這一片段XML:

<fragment 
        android:id="@+id/place_autocomplete_fragment" 
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="1"/> 

該片段應代表這你上面呈現的搜索欄。此片段將執行Google地方信息自動填充搜索的所有邏輯。下面你有這樣的片段也java的用法:

PlaceAutocompleteFragment _autocompleteFragment = (PlaceAutocompleteFragment) 
       getActivity() 
         .getFragmentManager() 
         .findFragmentById(R.id.place_autocomplete_fragment); 
     _autocompleteFragment.setOnPlaceSelectedListener(_placeSelectedListener); 

而且回調實現:

private PlaceSelectionListener _placeSelectedListener = new PlaceSelectionListener() { 
     @Override 
     public void onPlaceSelected(Place place) { 
      //Place model has all data about Location selected from search box 
     } 

     @Override 
     public void onError(Status status) { 
     } 
    }; 

欲瞭解更多信息,您可以查看文檔: https://developers.google.com/places/android-api/autocomplete