我的按钮出了什么问题。你能帮帮我吗?

时间:2016-10-10 05:41:02

标签: android mysql android-studio button php-mysqlidb

这是我的php文件。

<?php
 //Getting the requested id
$id = $_GET['id'];
 //Importing database
require_once 'include/Config.php';
 //Creating sql query with where clause to get an specific student
 $sql = "INSERT INTO bus_one (name,address,grade_level,pick_up,dismiss)     SELECT name,address,grade_level,pick_up,dismiss FROM students";
 //getting result 
$r = mysqli_query($con,$sql);
 //pushing result to an array
$result = array();
$row = mysqli_fetch_array($r);
array_push($result,array(
"id"=>$row['id'],
"name"=>$row['name'],
"add"=>$row['address'],
"grad"=>$row['grade_level'],
"pick"=>$row['pick_up'],
"dis"=>$row['dismiss']
));

//displaying in json format
echo json_encode(array('result'=>$result));
mysqli_close($con);
?>

这是我的按钮。

private void sendStudent() {

    class sendStudent extends AsyncTask<Void, Void, String> {

        ProgressDialog loading;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(BusNumberList.this, "Sending...", "Wait...", false, false);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            Toast.makeText(BusNumberList.this,s,Toast.LENGTH_LONG).show();
        }

        @Override
        protected String doInBackground(Void... params) {
            RequestHandler rh = new RequestHandler();
            String s = rh.sendGetRequestParam(Config.URL_SAVING_TO_BUS_ONE, id);
            return s;
        }
    }
    sendStudent de = new sendStudent();
    de.execute();
}

这就是我想要发生的原因。当我单击按钮时,它将自动获取学生详细信息并将其复制到我的第二个表格。当我运行PHP文件时,它正在运行,但是当我尝试调试应用程序时按钮不起作用。你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

There are many ways of calling the function on a button's click.

Option 1. Assign function to button's view in xmlfile:
   android:onClick="sendStudent"

If this is the case, then replace "private void sendStudent() {"
with "public void sendStudent(View view) {"

Option 2. You can also set OnClickListener. Add below code in your OnCreate method. 

Button b = (Button) findViewById(R.id.button); //Use your button Id
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendStudent(); //Calling method for execution on button click
            }
        });