Here's my php file.
这是我的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);
?>
Here's my button.
这是我的按钮。
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();
}
This is why I want to happen. When I Click the button it will automatically get the student details and transfer copy it to my 2nd table. When I run the PHP
file it is working but when I try debugging the app the button is not working. Can you help me with this?
这就是我想要发生的原因。当我单击按钮时,它将自动获取学生详细信息并将其复制到我的第二个表格。当我运行PHP文件时,它正在工作,但是当我尝试调试应用程序时按钮不起作用。你能帮我解决这个问题吗?
1 个解决方案
#1
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
}
});
#1
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
}
});