解决方案:
对的,这是可能的。请按照以下步骤操作:
第 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)
,它必须与此解决方案中显示的相同。
而已。希望对你有帮助。有什么问题,欢迎评论。