android - 将按钮添加到自动完成搜索框
android - add button to auto complete search box
我已经在我的 android 应用程序中实现了 Google 的 PlaceAutocompleteFragment
,如下所示。
但我想在最后添加一个按钮 google 地图有麦克风。
到目前为止我的代码如下:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
>
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
</android.support.v7.widget.CardView>
地点select代码:
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
String placeName = place.getName().toString();
LatLng latLng = place.getLatLng();
mMap.addMarker(new MarkerOptions().position(latLng).title(placeName));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
有示例代码就好了。非常感谢:)
非常抱歉这么晚才回复,但由于一些错误,我已经重新安装并下载了整个 Android Studio 和 SDK
这是我给你的建议:-
- 使用第 3 个库 FloatingSearchView
自定义你自己,但是这将分别花费一些时间到第三个库,这里有一些简单的教程可以帮助你 Custom Google Place Autocomplete Android and
是尝试深入Google的代码来定制它知道这将通过扩展Google的class和复制Google 的整个代码然后编辑它是一个重新生成的 class
此外,我深入了解代码的最后一步是知道此方法是创建 Google 搜索的方法
private void zzzG() {
int var1 = -1;
try {
Intent var2 = (new PlaceAutocomplete.IntentBuilder(2)).setBoundsBias(this.zzaRk).setFilter(this.zzaRl).zzeq(this.editSearch.getText().toString()).zzig(1).build(this.getActivity());
this.startActivityForResult(var2, 1);
} catch (GooglePlayServicesRepairableException var3) {
var1 = var3.getConnectionStatusCode();
Log.e("Places", "Could not open autocomplete activity", var3);
} catch (GooglePlayServicesNotAvailableException var4) {
var1 = var4.errorCode;
Log.e("Places", "Could not open autocomplete activity", var4);
}
if (var1 != -1) {
GoogleApiAvailability var5 = GoogleApiAvailability.getInstance();
var5.showErrorDialogFragment(this.getActivity(), var1, 2);
}}
此外,如果您对这些解决方案有任何疑问,请给我反馈
我已经在我的 android 应用程序中实现了 Google 的 PlaceAutocompleteFragment
,如下所示。
但我想在最后添加一个按钮 google 地图有麦克风。
到目前为止我的代码如下:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
>
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
</android.support.v7.widget.CardView>
地点select代码:
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
String placeName = place.getName().toString();
LatLng latLng = place.getLatLng();
mMap.addMarker(new MarkerOptions().position(latLng).title(placeName));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
有示例代码就好了。非常感谢:)
非常抱歉这么晚才回复,但由于一些错误,我已经重新安装并下载了整个 Android Studio 和 SDK
这是我给你的建议:-
- 使用第 3 个库 FloatingSearchView
自定义你自己,但是这将分别花费一些时间到第三个库,这里有一些简单的教程可以帮助你 Custom Google Place Autocomplete Android and
是尝试深入Google的代码来定制它知道这将通过扩展Google的class和复制Google 的整个代码然后编辑它是一个重新生成的 class
此外,我深入了解代码的最后一步是知道此方法是创建 Google 搜索的方法
private void zzzG() { int var1 = -1; try { Intent var2 = (new PlaceAutocomplete.IntentBuilder(2)).setBoundsBias(this.zzaRk).setFilter(this.zzaRl).zzeq(this.editSearch.getText().toString()).zzig(1).build(this.getActivity()); this.startActivityForResult(var2, 1); } catch (GooglePlayServicesRepairableException var3) { var1 = var3.getConnectionStatusCode(); Log.e("Places", "Could not open autocomplete activity", var3); } catch (GooglePlayServicesNotAvailableException var4) { var1 = var4.errorCode; Log.e("Places", "Could not open autocomplete activity", var4); } if (var1 != -1) { GoogleApiAvailability var5 = GoogleApiAvailability.getInstance(); var5.showErrorDialogFragment(this.getActivity(), var1, 2); }}
此外,如果您对这些解决方案有任何疑问,请给我反馈