私はVolleyを使用して複数のリクエストにヒットしようとしていますが、すべてのリクエストに対して応答を得ています。私の問題は、応答を特定する方法がどのAPIに属しているかです。Androidボレーの複数のリクエストを処理します
mQueue = CustomVolleyRequest.getInstance(this.getApplicationContext())
.getRequestQueue();
final CustomJSONObjectrequest jsonRequest = new CustomJSONObjectrequest(Request.Method
.GET, url,
new JSONObject(), this, this); //
jsonRequest.setTag(REQUEST_TAG);
final CustomJSONObjectrequest jsonRequest2 = new CustomJSONObjectrequest(Request.Method
.GET, url2,
new JSONObject(), this, this);
jsonRequest2.setTag(REQUEST_TAG);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mQueue.add(jsonRequest);
mQueue.add(jsonRequest2); // Both the request will have different API request
}
});
}
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText(error.getMessage());
}
@Override
public void onResponse(Object response) {
// How to identify, which response is belong to which api request
mTextView.setText("Response is: " + response);
}
を含めたいあなたのクラスで
に取得するためのインタフェースを使用してください。私の親クラスのリスナーと私はmのOnResponseメソッドをオーバーライドしますy parent.thenタグなどを使用して識別する方法はありますか? –
'Response.Listener'インタフェースを実装する抽象クラスを作成し、2つのパラメータを取るようにすることができます.2つ目はタグです。 –
私はそのようにしています。 OnResponse(Obj)には、1つのパラメータしかありませんでした。私たちがリクエストのためにTAGを特定する方法や、間違っている場合、少し詳しく説明することができます。 –