I have a ListView
with more than 40 items and I want to save their details on MySQL. All works well for the first 4-5 items then the loop stops without any error.
String student,obtained_value,max_value;
for (int i=0;i<listStudent.getChildCount();i++) {
View view=listStudent.getChildAt(i);
studentIdTxt=(TextView) view.findViewById(R.id.student_id_ls);
obtainedTxt=(EditText) view.findViewById(R.id.obtained);
maxTxt=(TextView) view.findViewById(R.id.max);
student=studentIdTxt.getText().toString();
obtained_value=obtainedTxt.getText().toString();
max_value=maxTxt.getText().toString();
//updating the new mark list array
/*HashMap<String,String>studentMark=new HashMap<String,String>();
studentMark.put(TAG_STUDENT_ID,student);
studentMark.put(TAG_MARKS_OBTAINED,obtained_value);
studentMark.put(TAG_MARKS_MAX, max_value);*/
//studentMarksList.add(studentMark);
//transform studentMarksList to json
//String studentList=gson.toJson(studentMarksList);
String URL_CHECK=domain+"/app/caller.php?action=save_marks&work_id="+workId+"&student="+student+"&obtained="+obtained_value+"&max="+max_value+"&course="+course+"&staff="+staff;
String response=caller.makeServiceCall(URL_CHECK,serviceHandler.POST);
boolean result=false;
Log.d("Response: ", "> " + response);
if (response != null) {
try {
JSONObject jsonObj = new JSONObject(response);
// Getting JSON Array node
ServerReply = jsonObj.getJSONArray(TAG_CHECK_RESULT);
JSONObject c=ServerReply.getJSONObject(0);
String error_txt= c.getString(TAG_ERROR_TXT);
String error_code=c.getString(TAG_ERROR_CODE);
String message=c.getString(TAG_MESSAGE);
if(error_txt.equals("success")){
result=true;
}else{
result=false;
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
}
The commented lines were used when I tried to put them in an array then send them all at once as JSON, but it didn't worked.
How can I save all the items from the ListView
without the loop stopping?