William Willi William Willi - 4 months ago 10
Android Question

how to pass two Strings in "StringRequest" in android

i want to get data from two different tables in MYSQL so i used "StringRequest" method to retrieve data from MYSQL, In the below code i can get data from one table and view it in ListView in android but how i can change my code so that i will get data from another table too.

here is my code:

String url ="http://alwaysready.16mb.com/OnlineJobSort.php;";
String url_lock="http://alwaysready.16mb.com/LocalSort.php?";

StringRequest stringRequest = new StringRequest(URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Jobs.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
}
});

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);


From the above code i can able to get data from "url" but i need to get data from both "url"&"url_lock".

Answer

Well, it's simple. You just need to make 2 StringRequests with different URL parameter

String url = "http://alwaysready.16mb.com/OnlineJobSort.php;";
String url_lock = "http://alwaysready.16mb.com/LocalSort.php?";

StringRequest stringRequest1 = new StringRequest(url, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        showJSON(response);
    }
},
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Jobs.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
            }
        });

StringRequest stringRequest2 = new StringRequest(url_lock, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        showJSON(response);
    }
},
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Jobs.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
            }
        });

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest1);
requestQueue.add(stringRequest2);