Android Places auto complete正在打开一个新的覆盖谷歌搜索
我正在使用谷歌的自动完成地点小部件。我注意到,当我把它放在我的活动中并点击它时,它会在我的活动顶部打开一个片段(虽然我的活动是全屏的,但有一个状态栏) 我如何将整个行为嵌入到我的活动中,从而使被单击以启动搜索的小部件实际上是填充了建议的同一个小部件Android Places auto complete正在打开一个新的覆盖谷歌搜索,android,google-places,googleplacesautocomplete,Android,Google Places,Googleplacesautocomplete,我正在使用谷歌的自动完成地点小部件。我注意到,当我把它放在我的活动中并点击它时,它会在我的活动顶部打开一个片段(虽然我的活动是全屏的,但有一个状态栏) 我如何将整个行为嵌入到我的活动中,从而使被单击以启动搜索的小部件实际上是填充了建议的同一个小部件 <androidx.cardview.widget.CardView android:layout_width="0dp" android:layout_height="wrap_content" android:l
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="@+id/ibLocationAction"
app:layout_constraintEnd_toStartOf="@+id/ibLocationAction"
app:layout_constraintStart_toEndOf="@+id/ibClose"
app:layout_constraintTop_toTopOf="@+id/ibLocationAction">
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.cardview.widget.CardView>
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i(GlobalVar.TAG, "Place: " + place.getName());
chosenPlace = place;
}
@Override
public void onError(Status status) {
Log.i(GlobalVar.TAG, "An error occurred: " + status);
}
});
PlaceAutocompleteFragment autocompleteFragment=(PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(新的PlaceSelectionListener(){
@凌驾
已选定地点上的公共作废(地点){
Log.i(GlobalVar.TAG,“Place:+Place.getName());
chosenPlace=地点;
}
@凌驾
公共作废申报人(状态){
Log.i(GlobalVar.TAG,“发生错误:+状态”);
}
});
根据放置自动完成文档,您可以在覆盖模式下使用自动完成小部件(称为“模式覆盖”),也可以在全屏模式下使用自动完成小部件(称为模式全屏)。
当我第一次了解place autocomplete时,我也遇到了这个问题,但似乎你无法实现与按下的视图的交互,你只能在上面提到的模式全屏和模式覆盖之间进行选择(全部根据文档)你所说的充满提示的同一个小部件是什么意思,现在还不是很清楚,如果你点击嵌入到活动xml中的搜索小部件,它会在上面显示另一个“谷歌搜索小部件”,就好像它是一个新的活动一样。我想与原始的widget交互,而不是新的覆盖widget检查我的答案-希望它能帮助您问题在于您提到的是使用intent的文档中的选项2。我正在使用选项1,它应该是嵌入式的!我会尽量让它更清楚一点-选项1或模式重叠基本上是你当前布局上的另一个搜索片段,选项2是在新屏幕上打开的另一个搜索片段。我理解你关于意图的问题,但是不要写很长的评论,看一看,希望这能帮助你我给你看了我写的代码。事情是这样的,这不是故意的。网站中的选项1指的是只调用片段,没有意图,没有模式。你知道我的意思吗?是的,我认为即使你正在校准一个片段,它也会在顶部打开一个新片段,你不能真正使用你原来的搜索视图。我可以说这是合乎逻辑的-如果谷歌允许,我想当你在屏幕底部使用搜索视图时可能会出现问题,而且用户将没有屏幕空间来选择选项(希望这是明确的)Yea是有意义的。我认为他们应该去掉选项1,这样其他人就不会像我一样感到困惑了。非常感谢。