2017-05-29 10 views
0

私のアプリケーションのフラグメントに実装するには、Googleのプレースオートコンプリート(https://developers.google.com/places/android-api/autocomplete)を使用しようとしています。しかし、私はこれは、XMLファイルフラグメントを拡張するクラスにGoogleのPlaceAutoCompleteFragmentを実装する方法

<RelativeLayout 
    android:id="@+id/someRelativeLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="36dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="30dp" 
    android:background="@drawable/some_drawable"> 
    <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="wrap_content" /> 
</RelativeLayout> 
である。これは、Javaコード

private PlaceAutocompleteFragment mSearchPAF; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    View view = inflater.inflate(R.layout.some_layout, container, false); 
    mSearchLocationPAF = (PlaceAutocompleteFragment) parentActivity.getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); 
} 

であるこの断片中に戻ってくる

Caused by: java.lang.IllegalArgumentException: Binary XML file line #30: Duplicate id 0x7f0f010f, tag null, or parent id 0x7f0f00c0 with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment 
        at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2148) 

、他のフラグメントに、このフラグメントからナビゲートするときにこのエラーを持って、

私はこの同じjavaとxmlファイルに別のマップフラグメントもありますが、私はこのポスト(Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment)の答えに従って解決することができましたが、このPlace Aut ocompleteフラグメント

+0

自分の「PlaceAutoComplete」にIDを渡してください。 – tahsinRupam

+0

@ tahsinRupamそれはどういう意味ですか?どのような例ですか? –

+0

これは、2つの異なる 'PlaceAutoComplete'フラグメントで同じIDを使用している可能性があります。 – tahsinRupam

答えて

1

私は、Android Studioでまだ初心者(私は現在、私のプロジェクトに取り組んでおり、複数の断片と私の主な活動を実施していますここでの回答の1 Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment

private PlaceAutocompleteFragment mSearchPAF; 
@Override 
public void onDestroyView() { 
    super.onDestroyView(); 
    PlaceAutocompleteFragment f = (PlaceAutocompleteFragment) getFragmentManager() 
            .findFragmentById(R.id.place_autocomplete_fragment); 
    if (f != null) 
     getFragmentManager().beginTransaction().remove(f).commit(); 
} 
1

に従うことによって、この問題を自分で解決しています)。私のナビゲーションの断片では、Googleが提供するgoogleAutocompleteを使用しました。

このコードは、OnCreateView()内で実装されています。

mPlace_Starting = (PlaceAutocompleteFragment) 
 
     this.getChildFragmentManager().findFragmentById(R.id.place_starting); 
 

 
AutocompleteFilter countryFilter = new AutocompleteFilter.Builder() 
 
     .setTypeFilter(Place.TYPE_COUNTRY) 
 
     .setCountry("PH") 
 
     .build(); 
 

 
mPlace_Starting.setFilter(countryFilter); 
 

 
mPlace_Starting.setOnPlaceSelectedListener(new PlaceSelectionListener() { 
 
    @Override 
 
    public void onPlaceSelected(Place place) { 
 
     // TODO: Get info about the selected place: 
 
     Log.i(TAG, "Starting Place:" + place.getName()); 
 
     Toast.makeText(getActivity(), "Starting Place: " + place.getName(), 
 
       Toast.LENGTH_SHORT).show(); 
 

 
     double mLongitude = place.getLatLng().longitude; 
 
     double mLatitude = place.getLatLng().latitude; 
 

 
     mStartingpoint = new Waypoint(mLongitude,mLatitude); 
 
     mStartpoint = new GeoCoordinate(mLongitude,mLatitude); 
 
    } 
 
    @Override 
 
    public void onError(Status status) { 
 
     //TODO: Handle the Error. 
 
     Log.i(TAG, "An error occured: " + status); 
 
    } 
 
});

ウィジェットが別の断片(私のナビゲーションフラグメント)内で膨張する断片であるので、私はgetChildFragmentManager()を使って、Googleからの私のPlaceAutocompleteFragmentウィジェットを膨らま。

+0

このリンクで質問に答えることができますが、ここでの回答と参照用のリンクを提供します。リンクされたページが変更された場合、リンクのみの回答は無効になります。 - [レビューより](/レビュー/低品質の投稿/ 17139659) – MikeT

関連する問題