Question

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?

Was it helpful?

Solution

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);    

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top