1

私はToggleButtonを持っています。チェックした場合はデータベースmysqlにアイテムを挿入し、そうでない場合はmysqlからアイテムを削除します。最初の関数は機能しますが、2番目の関数はそれを示していません。

10-25 16:14:05.618: D/Delete student In manage(401): {"message":"No student found","success":0}

ToggleButtonのチェックをクリックする前に挿入するので、学生は資金であると確信しています。

toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        if (isChecked) {
                            // absent
                            id = student.get(holder.position)
                                    .get(TAG_StudentID);
                            new ManageAttendance().execute();

                        } else {
                            id = student.get(holder.position)
                                    .get(TAG_StudentID);
                            new DeleteInManage().execute();


                        }
                    }
                });

コード全体

public class MyCustomAdapter extends ArrayAdapter<HashMap<String, String>> {

    JSONParser jsonParser = new JSONParser();

    private static String url_delete_in_manage = "http://10.0.2.2/SmsPhp/delete_in_manage.php";
@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(resource, parent, false);
            holder = new ViewHolder();
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.position = position;

        holder.toggle
                .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked) {
                        if (isChecked) {
                            // absent
                            id = student.get(holder.position)
                                    .get(TAG_StudentID);
                            new ManageAttendance().execute();

                        } else {
                            id = student.get(holder.position)
                                    .get(TAG_StudentID);
                            new DeleteInManage().execute();


                        }
                    }
                });


        return convertView;

    }

    private static class ViewHolder {

        ToggleButton toggle;
    }

    /*****************************************************************
     * Background Async Task to Delete student

    /*****************************************************************
     * Background Async Task to Delete student
     * */
    class DeleteInManage extends AsyncTask<String, String, String> {

        protected String doInBackground(String... args) {
            final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH);
            mDay = c.get(Calendar.DAY_OF_MONTH);
            Date = mYear + "-" + mMonth + "-" + mDay;

            c1 = "77";
        Status ="A";
            // Check for success tag
            int success;
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("StudentID", id));
                params.add(new BasicNameValuePair("Date", Date));
                params.add(new BasicNameValuePair("SectionID", c1));
                params.add(new BasicNameValuePair("Status", Status));

                // getting student details by making HTTP request
                JSONObject json = jsonParser.makeHttpRequest(
                        url_delete_in_manage, "POST", params);

                // check your log for json response
                Log.d("Delete student In manage ", json.toString());

                // json success tag
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    // student successfully deleted

                }

            } catch (JSONException e) {

                e.printStackTrace();
            }

            return null;
        }

    }


}

削除したいときに呼び出すphpコード

<?php

/*
 * Following code will delete a student from table
 * A student is identified by student id 
 */
// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['StudentID']) && isset($_POST['Date']) && isset($_POST['SectionID']) && isset($_POST['Status']))
 {
    $StudentID = $_POST['StudentID'];
      $Date = $_POST['Date'];
        $SectionID = $_POST['SectionID'];
           $Status  = $_POST['Status'];

    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();

    // mysql update row with matched pid
    $result = mysql_query("DELETE FROM attends WHERE StudentID = $StudentID && Date=$Date && SectionID=$SectionID && Status =$Status " );

    // check if row deleted or not
    if (mysql_affected_rows() > 0) 
    {
        // successfully updated 
        $response["success"] = 1;
        $response["message"] = " student successfully deleted";

        // echoing JSON response
        echo json_encode($response);
    } else
    {
        // no Section found
        $response["success"] = 0;
        $response["message"] = "No student found";

        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

私がそれを解決するのを手伝ってくれませんか

4

0 に答える 0