0

在去之前我有一个活动autocomplete activity。我想将上一个活动的数据作为 aString extra发送到 Google 自动完成功能,并将其作为查询字符串显示在搜索栏上。这可能吗?

这是我的代码

Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN).build(this);
startActivityForResult(intent, REQUEST_GOOGLE_PLACE_AUTOCOMPLETE);

在此处输入图像描述

4

3 回答 3

1

到目前为止,我无法收到解决方案,所以我尝试检查PlaceAutocomplete.class并找到了我一直在寻找的解决方案。

通过查看

public final PlaceAutocomplete.IntentBuilder zzh(@Nullable String var1) {
        if (var1 != null) {
            this.intent.putExtra("initial_query", var1);
        } else {
            this.intent.removeExtra("initial_query");
        }

        return this;
    }

并打电话Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN).zzh("dasdas").build(this);

解决了这个问题。保存以供将来参考

于 2018-10-23T08:33:55.630 回答
0

解决方案:

对的,这是可能的。请按照以下步骤操作:

第 1步:intent.putExtra(..)使用[as we always do]将您的搜索字符串从一个活动发送到另一个活动

Step2:在下一个活动中使用getStringExtra(..)[as we always do]接收字符串

Step3:在之前声明一个全局对象onCreate()

public PlaceAutocompleteFragment autocompleteFragment;

第四步:初始化:

autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

Step5:接下来,将搜索栏投射到EditText并将您的字符串设置为文本,如下所示:

((EditText)autocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setText(your_string); [from previous activity]

注意:不要更改此行getView().findViewById(R.id.place_autocomplete_search_input),它必须与此解决方案中显示的相同。

而已。希望对你有帮助。有什么问题,欢迎评论。

于 2018-10-23T06:49:49.607 回答
0

我正在使用Autocomplete包中的类

com.google.android.libraries.places.widget

自动完成有一个方法setInitialQuery()

我将通过传递查询字符串和 latlng 参数来启动活动:

private void startAutocompleteActivity(String query) {
        List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG);
        Intent intent = new Autocomplete.IntentBuilder(
                AutocompleteActivityMode.FULLSCREEN, fields)
                .setTypeFilter(TypeFilter.ADDRESS)
                .setInitialQuery(query)
                .setLocationBias(RectangularBounds.newInstance(new LatLng(10.637859, 76.691510), new LatLng(11.345122, 77.324748)))
                .build(this);
        startActivityForResult(intent, REQUEST_SOURCE_LOCATION);
    }
于 2019-11-24T05:06:35.093 回答