php - Android在for循环中调用php

标签 php android mysql listview

我有一个包含 40 多个项目的 ListView,我想将它们的详细信息保存在 MySQL 上。前 4-5 个项目一切正常,然后循环停止,没有任何错误。

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");
    }
}

当我尝试将它们放入数组中然后将它们作为 JSON 一次性发送时,使用了注释行,但它不起作用。

如何在不停止循环的情况下保存 ListView 中的所有项目?

最佳答案

网络 I/O 速度慢。您需要将缓慢的 I/O 操作移出主线程(UI 线程)。你可以尝试一下AsyncTask。如果您可以显示 logcat 输出,这会有所帮助。

关于php - Android在for循环中调用php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080049/

相关文章:

php - 使用 php 创建自定义的谷歌地图

java - 如何在 Android 中全局保存 "list"或至少实例以供在任何 Activity 中使用?

java - 带参数的单例

javascript - PHP 写入文件时行结尾错误

php - Laravel 简单月份选择

php - CodeIgniter 和计算数据库中的特定行

Android:以编程方式检测设备是否连接了硬件触摸屏

MySQL 按 X 排序,但先对 Y 中的两个进行排序

mysql - 使用 docker-compose 的 Rails 应用程序不会连接到 mysql 容器

php - mysql 连接 symfony + docker