Reputation: 3021
I am using Volley StringRequest to make GET call to web services using following code.
ArrayList<HashMap<String, Object>> list;
StringRequest getRequest = new StringRequest(Request.Method.GET,activity.getString(R.string.URL),
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
int success;
//Parsed data and Want to return list
//return list;
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error.Response", error.toString());
}
});
request.add(getRequest);
Any idea how do I return the list data?
Upvotes: 2
Views: 4623
Reputation: 951
In your case you have a list defined just outside the Volley request. Just assign the new data from where you receive the data.
list = yourNewList;
or use interfaces.
However you are using a StringRequest and you will only get a String as a response from the server. You will have to parse the String yourself and build up the list.
If you are expecting a JSON respons you can use JsonArrayRequest or JsonObjectRequest instead of StringRequest.
Upvotes: 0
Reputation: 682
Use interface as listeners and return the data
public interface DataListener {
void onDataReceived(ArrayList<HashMap<String, Object>> response);
void onError(DataResponse resp); }
then in onResponse
datalistener.onDataReceived(list);
Upvotes: 1