亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在“查找當前位置”中獲取以后可以單獨選擇的響應響應

如何在“查找當前位置”中獲取以后可以單獨選擇的響應響應

繁花如伊 2022-09-22 20:12:00
我需要做一個活動,允許用戶點擊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));  }
查看完整描述

1 回答

?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

字符串化就是這樣做的?;貞旧硪呀浭恰盎貞?。你可能需要一個帶有回調的接口才能將結果添加到磁貼列表中。


// 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


   }

};


查看完整回答
反對 回復 2022-09-22
  • 1 回答
  • 0 關注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號