2016-03-18 26 views
1
> public void makeJsonObjectRequest(Long s,Double lat, Double lon, int 
> timezone) { 
>   String urlJsonObj = "http://projet.dev.e-njaz.com/api/example/getPrayerTimes/" + s + "/" + 
> lat + "/" + lon + "/" + timezone; 
>   JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, 
>     urlJsonObj, null, new Response.Listener<JSONObject>() { 
>    @Override 
>    public void onResponse(JSONObject response) { 
>     Log.d(TAG, response.toString()); 
>     try { 
>      DateFormat i=new SimpleDateFormat("HH:mm"); 
>      DateFormat o = new SimpleDateFormat("KK:mm a"); 
>      prayertimes.setStr_asarr(response.toString()); 
>      prayertimes.str_ishaa=o.format(i.parse(response.getString("6").toString())); 
>     } catch (JSONException e) { 
>      e.printStackTrace(); 
>     } catch (ParseException e) { 
>      e.printStackTrace(); 
>     } 
>    } 
> 
>   }, new Response.ErrorListener() { 
>    @Override 
>    public void onErrorResponse(VolleyError error) { 
>     VolleyLog.d(TAG, "Error: " + error.getMessage()); 
>     Toast.makeText(getApplicationContext(), 
>       error.getMessage(), Toast.LENGTH_SHORT).show(); 
>    } 
>   }); 
>   AppController.getInstance().addToRequestQueue(jsonObjReq); 
>   
>  } 

hello evrybody,我需要返回函數onReponse中的對象付款人次,請你幫我。當我改變onReponse的類型返回時,我有一個錯誤。我需要返回排球庫的結果

回答

1

您必須使用'回調'才能從抽排中返回值。它是一個相當複雜的方法,所以我會建議一個替代方案你應該在活動中創建一個變量並在onResponse中設置它的值,然後在你想要的任何函數中使用該變量(你甚至可以在o​​nResponse中調用該函數)。

如果你仍然想嘗試返回一個值,然後檢查this

如果你不明白的東西把它留在評論

相關問題