I want to send all the data from the SQLite database in the following way:
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
SQLiteDatabase db = basededatos.getReadableDatabase();
Cursor cursor = db.query("aguacate", new String[] {"calibre","precio","porcentaje","resultado",},null, null, null, null, null);
if (cursor.moveToFirst()) {
//Recorremos el cursor hasta que no haya más registros
do {
parameters.put("calibre",cursor.getString(1));
parameters.put("precio", cursor.getString(2));
parameters.put("porcentaje", cursor.getString(3));
parameters.put("resultado", cursor.getString(4));
} while(cursor.moveToNext());
}
return parameters;
}
};
requestQueue.add(request);
But how can I put the
requestQueue.add(request);
inside the while loop? It won't let me, is there a solution?
Inside the cycle
while
it will not leave you since it is inside the section where the parameters that will be sent in the loop are assigned.StringRequest
As I understand your question, you need to make a request through
StringRequest
for each record of your query, for which I recommend that you first make a function that iterates your query, consume another function that is called with each record found, for which I would propose something like that:Code of the function that generates the results for each request
Code of the function that executes the requests
I also recommend that you do variable handling in case one is null and an exception is not thrown.
Update
The variable is declared
parameters
asfinal
so that the code does not mark errors