[英]updating the value of attribute in database after clicking the positive button of the alertbox
I am showing an alert dialogue box on my app, and what I want is as soon as I click the positive button of the alert box it should change the value of an attribute in my database, I know how to do it in the php side but I am not getting how to do it in android side, if someone can help please? 我在我的应用程序上显示一个警告对话框,而我想要的是,只要单击警告框的肯定按钮,它就应该更改数据库中属性的值,我知道如何在php端进行操作但是如果有人可以帮助,我在android方面无法做到这一点? Here is the code:
这是代码:
AlertDialog.Builder builder1 = new AlertDialog.Builder(ctx);
builder1.setMessage(result);
builder1.setCancelable(true);
builder1.setPositiveButton(
"accept", // this is the button that would change the value of attribute in the database
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ctx.startActivity(new Intent(ctx, emergency.class));
dialog.cancel();
}
});
builder1.setNegativeButton(
"reject",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
Or you can use Volley library to do it. 或者,您可以使用Volley库来做到这一点。
php code: php代码:
<?php
$edit_id=$_GET['edit_id'];
$vallue=$_GET['value'];
require_once 'config.php';
mysql_set_charset('utf8');
mysql_query("update tbl set `value`='{$value}' where `edit_id`='{$edit_id}'");
if(mysql_affected_rows()==1)
{
echo 'updated';
}
else
{
echo mysql_error();
}
mysql_close();
?>
Your Alert Builder code 您的Alert Builder代码
AlertDialog.Builder builder1 = new AlertDialog.Builder(ctx);
builder1.setMessage(result);
builder1.setCancelable(true);
builder1.setPositiveButton(
"accept", // this is the button that would change the value of attribute in the database
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
changeValue("your domain.php?edit_id="+edit_id+"&value="+value);
dialog.cancel();
}
});
builder1.setNegativeButton(
"reject",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
Not come to volley part: 不在排球部分:
public void changeValue(String url)
{
final ProgressDialog pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.show();
StringRequest strReq = new StringRequest(Request.Method.GET,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d(TAG, response.toString());
try{
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
}catch(Exception ex){
Toast.makeText(getApplicationContext(), ex.toString(), Toast.LENGTH_LONG).show();
}
pDialog.hide();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
});
//Adding request to request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(strReq);
}
Now you can use it to edit the entry in database 现在您可以使用它来编辑数据库中的条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.