有人在 jetpack 撰写项目中实现了谷歌自动完成建议文本字段或片段吗?如果是这样,请指导或分享代码片段,因为我在实现它时遇到困难。
更新
这是我触发打开全屏对话框的意图,但是当我开始在其中输入时,它会被关闭,而且我也无法弄清楚问题是什么,并且需要有关处理活动结果的线索以供阅读此 compose 函数内的预测结果。
Places.initialize(context, "sa")
val fields = listOf(Place.Field.ID, Place.Field.NAME)
val intent = Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN,fields).build(context)
startActivityForResult(context as MainActivity,intent, AUTOCOMPLETE_REQUEST_CODE, Bundle.EMPTY)
Run Code Online (Sandbox Code Playgroud) android google-places placeautocompletefragment android-jetpack-compose
Google最近更新了适用于Android的Places SDK,因此现在我也正在更新代码。我正在尝试使用AutocompleteSupportFragment
来允许用户设置其地址。
这是我的代码:
mAddressEditText = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.address);
mAddressEditText.setPlaceFields(Arrays.asList(Place.Field.ADDRESS, Place.Field.LAT_LNG));
mAddressEditText.setHint("Address");
mAddressEditText.setText("Test1"); // Works fine at the beginning, disappears after selecting a place and shows only the hint
mAddressEditText.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.d(TAG, "Place Selected");
// Other Stuff
mAddressEditText.setText("Test2"); // Doesn't Work, all I can see is the hint
mAddressEditText.setText(place.getAddress()); // Doesn't Work, all I can see is the hint
}
@Override
public void onError(Status status) {
Log.e(TAG, "An error occurred: " + status); …
Run Code Online (Sandbox Code Playgroud) android ×2