简体   繁体   English

单击警报框的肯定按钮后,更新数据库中的属性值

[英]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();
        }

When the button is clicked, you can setup an HTTP GET request to call your php file on the server with the desired GET parameters. 单击该按钮后,您可以设置HTTP GET请求,以使用所需的GET参数在服务器上调用您的php文件。 Check this link , this is one way of creating a request. 选中此链接 ,这是创建请求的一种方法。

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.

相关问题 如何使用数据库中的初始值填充AlertBox - How to populate AlertBox with initial value from the database 单击按钮后,在jcombobox中选择数据并在jtextfield中获取其相应的数据库值 - selecting the data in jcombobox and getting its corresponding database value in jtextfield after clicking the button 单击确定按钮后,JDialog上没有返回任何值 - No value is return on the JDialog after clicking ok button 单击按钮时未显示警报框 - Alertbox not showing on button click 单击按钮后如何使具有不可见属性的视图“可见” - How to make Views with an Invisible attribute 'Visible' after clicking a button 单击按钮后 JTextField 值未更新 - JTextField value is not updating after button click 单击按钮后Spring Boot删除数据库条目 - Spring boot delete database entry after clicking button 单击JFrame的关闭按钮后如何删除MySql数据库记录? - How to delete MySql database records after clicking close button of JFrame? 来自assert的假阳性在调用验证方法后更改值属性时ArgumentCaptor.getValue() - False positive from assertThat on ArgumentCaptor.getValue() when changing value attribute after call on verified method DatePicker-如何在单击提交按钮后保持选定的值 - DatePicker - how to keep the selected value after clicking on submit button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM