2

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?

AkshayT
  • 2,901
  • 2
  • 28
  • 32
  • 3
    Why -2? In case it does not show any research effort then I challenge X(who did it) to find any tutorial or similar question. After searching for 2 hrs I posted this question. – AkshayT Mar 13 '14 at 04:34

2 Answers2

1

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);    
NARESH REDDY
  • 682
  • 4
  • 11
0

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.

VonSchnauzer
  • 912
  • 11
  • 17