Android - 从地方获取最近的搜索 API
Android - Get recent searches from Places API
我想模拟 Google 地图的 "Recent Search" 功能。
具体来说,我有一个 AutoCompleteTextView 与 Google 个位置 API 相连。如果用户关注 AutoCompleteTextView(阈值 0),我想 return 两个最近的搜索并可以选择搜索所有最近的搜索。
我查看了文档,但找不到 return 近期历史记录的 public 方法。这是我必须存储在我自己的网络服务上并手动检索的东西吗?或者 Google 是否向 public 提供类似的东西?
例子
您可以通过从 textview
获取文本并将其存储在共享首选项或数据库中来存储最近搜索的地点。我建议共享首选项 though.Then 在 AutoCompleteTextview
上显示建议
首选项中的设置值:
// MY_PREFS_NAME - a static String variable like:
//public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Elena");
editor.putInt("idName", 12);
editor.commit();
从首选项中检索数据:
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.
}
你可以看这里:
http://systemout.net/2014/12/19/android-autocomplete-edittext-with-history/
我想模拟 Google 地图的 "Recent Search" 功能。
具体来说,我有一个 AutoCompleteTextView 与 Google 个位置 API 相连。如果用户关注 AutoCompleteTextView(阈值 0),我想 return 两个最近的搜索并可以选择搜索所有最近的搜索。
我查看了文档,但找不到 return 近期历史记录的 public 方法。这是我必须存储在我自己的网络服务上并手动检索的东西吗?或者 Google 是否向 public 提供类似的东西?
例子
您可以通过从 textview
获取文本并将其存储在共享首选项或数据库中来存储最近搜索的地点。我建议共享首选项 though.Then 在 AutoCompleteTextview
首选项中的设置值:
// MY_PREFS_NAME - a static String variable like:
//public static final String MY_PREFS_NAME = "MyPrefsFile";
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
editor.putString("name", "Elena");
editor.putInt("idName", 12);
editor.commit();
从首选项中检索数据:
SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
int idName = prefs.getInt("idName", 0); //0 is the default value.
}
你可以看这里:
http://systemout.net/2014/12/19/android-autocomplete-edittext-with-history/