I'm trying to display data from a database. I was able to do it, but I don't know how to only fetch data according the values I have. For example:
I have a value a = 5;
then data to display will be : data1
, data2
, data3
, data4
, data5
(< display 5 data).
But I don't know how to do that. Any help is appreciated. Here is my code:
//Temporary Value
final double a = Math.floor(Double.parseDouble(transportResultA) / 10);
final double b = Math.floor(Double.parseDouble(transportResultB)/10);
final double c = Math.floor(Double.parseDouble(transportResultC)/10);
Fetch data code :
for (int i = 0; i < response.length() ; i++) {
try {
JSONObject obj = response.getJSONObject(i);
Exercise exercise = new Exercise();
if (obj.getString("KindOf").equals(textKindOF.getText().toString()) && obj.getString("Type").equals("Cardio")) {
exercise.setTipe(obj.getString("KindOf"));
exercise.setJenis(obj.getString("Type"));
exercise.setMainmuscle(obj.getString("Name"));
exerciseList.add(exercise);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
If I change how many data I want to fetch, I change response.length()
to a data success only 5 data, but when I try to change obj.getString("Type").equals("Cardio")
with other type like obj.getString("Type").equals("Strength")
data didn't display. What seems to be wrong with my code?
Aucun commentaire:
Enregistrer un commentaire