I would like to ask about how to place a StringRequest inside a class, because it usually shows an error showing that it needs a Context to be able to work. I do not seem to ask for a Context context as a parameter. To be able to call a class that does the work and return a JSON, in order to work it, without having to repeat code.
StringRequest sRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String respuesta) {
//Toast.makeText(MainActivity.this, respuesta, Toast.LENGTH_LONG).show();
mostrarDatos(respuesta);
//textViewMuestra.setText(respuesta);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}){
@Override
protected Map<String, String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("dni", sDni);
return params;
}
};
RequestQueue colaSolicitudes = Volley.newRequestQueue(this);
colaSolicitudes.add(sRequest);}