java - 如何在 FindCurrentPlaceResponse 中获取可以稍后单独选择的单个响应
问题描述
我需要进行一项活动,允许用户单击 getLocation 按钮,该按钮又根据可能性得分返回地点列表。FindCurrentPlaceResponse 的响应返回 20 个项目,我希望它们以列表或卡片视图的形式出现,用户最终从中选择最合适的位置。如何使响应返回可以放入可点击列表的各个地方?
我已经关注并完全使用了https://github.com/googlemaps/android-places-demos上的 google places 文档来进行我的活动
这是文档中将列表转换为单个字符串的确切代码
@RequiresPermission(allOf = {ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE})
private void findCurrentPlaceWithPermissions() {
setLoading(true);
FindCurrentPlaceRequest currentPlaceRequest = FindCurrentPlaceRequest.newInstance(getPlaceFields());
Task<FindCurrentPlaceResponse> currentPlaceTask = placesClient.findCurrentPlace(currentPlaceRequest);
currentPlaceTask.addOnSuccessListener(
(response) ->
responseView.setText(StringUtil.stringify(response, isDisplayRawResultsChecked())));
currentPlaceTask.addOnFailureListener(
(exception) -> {
exception.printStackTrace();
responseView.setText(exception.getMessage());
});
currentPlaceTask.addOnCompleteListener(task -> setLoading(false));
}
解决方案
Stringify 就是这样做的。响应本身已经是“响应”。您可能需要一个带有回调的接口来将结果添加到图块列表中。
// The callback interface
interface MyCallback {
void callbackCall(List<String> response);
}
// The class that takes the callback
class Worker {
MyCallback callback;
void onEvent(List<String> response) {
callback.callbackCall(response);
}
}
// Option 1: MainActivity or where the list is
class Callback implements MyCallback {
void callbackCall() {
// callback code goes here
// update your adaptor
}
}
worker.callback = new Callback();
// Option 2:
worker.callback = new MyCallback() {
void callbackCall(List<String> results ) {
// callback code goes here
}
};
推荐阅读
- django - 检测 Django CharField 中的 URL 和 #tags 并为其添加样式
- c++ - std::begin - 类型特征中不考虑用户定义的重载
- java - Java Android Bitmap.createBitmap 过早地超过了 src 位图宽度
- ibm-integration-bus - mqsisetdbparms 不使用特殊字符
- wordpress - 我无法让 wordpress 自定义页脚在关于我们的页面上工作
- sharepoint-online - 通过外部 gmail 用户访问 sharppoint 在线休息 api
- python - 如何迭代熊猫数据框中的行,如果满足条件,则将其打印在适当的 Excel 表中?
- scrapy - Scrapy - 来自爬行的响应没有与其外壳等效的相同编码
- android - 在 phonegap 应用程序中显示网页 - android
- php - 比较器在php上使用数组