Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何实现Google';将自动完成片段放入扩展片段的类中_Java_Android_Android Fragments_Google Places Api - Fatal编程技术网

Java 如何实现Google';将自动完成片段放入扩展片段的类中

Java 如何实现Google';将自动完成片段放入扩展片段的类中,java,android,android-fragments,google-places-api,Java,Android,Android Fragments,Google Places Api,我正试图使用Google的PlaceAutoComplete()在我的应用程序中实现一个片段。但是当我从这个片段导航到另一个片段,然后返回到这个片段时,我遇到了这个错误 Caused by: java.lang.IllegalArgumentException: Binary XML file line #30: Duplicate id 0x7f0f010f, tag null, or parent id 0x7f0f00c0 with another fragment for com.go

我正试图使用Google的PlaceAutoComplete()在我的应用程序中实现一个片段。但是当我从这个片段导航到另一个片段,然后返回到这个片段时,我遇到了这个错误

 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代码

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);
}
这是XML文件

<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和xml文件中还有另一个map片段,但我按照本文()中的答案设法解决了它,但我找不到任何解决此位置自动完成片段的方法


我已经按照这里的答案之一解决了这个问题


我目前正在做我的项目,并用多个片段实现了我的主要活动(仍然是Android Studio的新手)。在我的导航片段中,我使用了谷歌提供的googleAutocomplete

这里的代码是在OnCreateView()中实现的。
mPlace\u start=(PlaceAutocompleteFragment)
this.getChildFragmentManager().findFragmentById(R.id.place\u开始);
AutoCompleteTFilter countryFilter=新的AutoCompleteTFilter.Builder()
.setTypeFilter(地点.类型\国家)
.setCountry(“PH”)
.build();
mPlace_启动.setFilter(countryFilter);
mPlace\u start.setOnPlaceSelectedListener(新的PlaceSelectionListener(){
@凌驾
已选定地点上的公共作废(地点){
//TODO:获取有关所选地点的信息:
Log.i(标记“起始位置:+Place.getName());
Toast.makeText(getActivity(),“起始位置:”+Place.getName(),
吐司。长度(短)。show();
double mLongitude=place.getLatLng().经度;
double mLatitude=place.getLatLng()纬度;
mStartingpoint=新航路点(mLongitute,mLatitude);
mStartpoint=新的地理坐标(m纬度、m纬度);
}
@凌驾
公共作废申报人(状态){
//TODO:处理错误。
Log.i(标记“发生错误:+状态”);
}

});我目前正在从事我的项目,并用多个片段实现了我的主要活动(在Android Studio中还是个新手)。在我的导航片段中,我使用了谷歌提供的googleAutocomplete

这里的代码是在OnCreateView()中实现的。
mPlace\u start=(PlaceAutocompleteFragment)
this.getChildFragmentManager().findFragmentById(R.id.place\u开始);
AutoCompleteTFilter countryFilter=新的AutoCompleteTFilter.Builder()
.setTypeFilter(地点.类型\国家)
.setCountry(“PH”)
.build();
mPlace_启动.setFilter(countryFilter);
mPlace\u start.setOnPlaceSelectedListener(新的PlaceSelectionListener(){
@凌驾
已选定地点上的公共作废(地点){
//TODO:获取有关所选地点的信息:
Log.i(标记“起始位置:+Place.getName());
Toast.makeText(getActivity(),“起始位置:”+Place.getName(),
吐司。长度(短)。show();
double mLongitude=place.getLatLng().经度;
double mLatitude=place.getLatLng()纬度;
mStartingpoint=新航路点(mLongitute,mLatitude);
mStartpoint=新的地理坐标(m纬度、m纬度);
}
@凌驾
公共作废申报人(状态){
//TODO:处理错误。
Log.i(标记“发生错误:+状态”);
}

});
给自己的
PlaceAutoComplete
一个id。@tahsinRupam这是什么意思?有什么例子吗?这可能是因为您在两个不同的
PlaceAutoComplete
fragment中使用了相同的id。您在两个fragment中使用了相同的id吗PlaceAutocomplete@Sandeepdhiman如果你是这个意思(android:id=“@+id/place\u autocomplete\u fragment”)那就不要给你自己的
PlaceAutoComplete
。@tahsinRupam这是什么意思?有什么例子吗?这可能是因为您在两个不同的
PlaceAutoComplete
fragment中使用了相同的id。您在两个fragment中使用了相同的id吗PlaceAutocomplete@Sandeepdhiman如果你是这个意思(android:id=“@+id/place\u autocomplete\u fragment”),那么不是
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();
}