まず、あなたのvollyクラス
/** Callback interface for delivering parsed responses. */
public interface Listener {
/** Called when a response is received. */
public void onResponse(Object tag, JSONObject response);
public void onErrorResponse(Object tag, VolleyError error);
}
からの応答を与えるそして今、あなたがリスナーとタグを渡すところ、以下のような方法を作成し、volly要求を呼び出すリスナーを作成します。応答では、同時にタグと応答を得ることができます。
public void callApi(String url, final Listener listener, final Object tag){
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
listener.onResponse(tag,response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onErrorResponse(tag,error);
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}
サンプルコードは、あなたの要件を変更することができます。ヘルプのコメントが必要な場合。
これはあなたを助けるかもしれません[リンク](https://stackoverflow.com/questions/36127870/how-to-set-tag-to-the-request-and-get-it-from-response-volley-asynchronous -reque) –
@MohammedFarhanだから、私のアプリケーションでは、ボレーのソースコードをコンパイルする必要があるのですか? – FarshidABZ
その答えが受け入れられるので、それに従う必要があります。 –