如何在“查找当前位置”中获取以后可以单独选择的响应响应

我需要做一个活动,允许用户点击getLocation按钮,该按钮又根据可能性分数返回地点列表。来自FindCurrentPlaceResponse的响应返回20个项目,我希望它们以列表或卡片视图的形式出现,用户最终从中选择最合适的位置。如何使响应返回可放入可点击列表中的各个位置?


我已经遵循并完全使用谷歌地点文档 https://github.com/googlemaps/android-places-demos 我的活动


这是文档中将列表转换为单个字符串的确切代码


@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));

  }


繁花如伊
浏览 107回答 1
1回答

德玛西亚99

字符串化就是这样做的。回应本身已经是“回应”。你可能需要一个带有回调的接口才能将结果添加到磁贴列表中。// The callback interfaceinterface MyCallback {void callbackCall(List<String> response);}// The class that takes the callbackclass Worker {MyCallback callback;void onEvent(List<String> response) {&nbsp; callback.callbackCall(response);&nbsp; &nbsp;}}// Option 1: MainActivity or where the list isclass Callback implements MyCallback {&nbsp; void callbackCall() {&nbsp; &nbsp;// callback code goes here&nbsp; &nbsp;// update your adaptor&nbsp;&nbsp; &nbsp;}&nbsp;}worker.callback = new Callback();// Option 2:worker.callback = new MyCallback() {void callbackCall(List<String> results ) {&nbsp; // callback code goes here&nbsp; &nbsp;}};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java