dongzhuo0895 2016-07-19 03:20
浏览 44
已采纳

如何使用齐射使代码更新数据?

can you help me to make a simple code for update data to server using volley... please include the php file and java code.. this is my layout... and i have the database that was upload in 000webhost..

<?xml version="1.0" encoding="utf-8"?><LinearLayout     
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

    <TextView
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:text="Pengaturan"
        android:id="@+id/textView8"
        android:layout_gravity="center_horizontal"
        android:textStyle="bold"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="23sp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:text="Profil"/>
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:src="@drawable/line"/>

<RelativeLayout
    android:layout_width="345dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="10dp"
        android:text="Nama :"
        android:id="@+id/textView9" />
    <TextView
        android:text="E-Mail :"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="50dp"
        android:id="@+id/textView10" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="90dp"
        android:text="No Telpon :"
        android:id="@+id/textView11" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="130dp"
        android:text="Alamat :"
        android:id="@+id/textView12" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etnama"
        android:layout_alignBottom="@+id/textView9"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etemail"
        android:layout_alignBottom="@+id/textView10"
        android:layout_below="@+id/textView9"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etnotelpon"
        android:layout_alignBottom="@+id/textView11"
        android:layout_below="@+id/etemail"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etalamat"
        android:layout_below="@+id/etnotelpon"
        android:layout_alignParentEnd="true"
        android:layout_alignBottom="@+id/textView12"/>

    <Button
        android:id="@+id/btEditProfil"
        android:text="Edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_gravity="right"
        android:layout_below="@+id/etalamat"/>

</RelativeLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="23sp"
    android:layout_marginTop="25dp"
    android:layout_marginLeft="15dp"
    android:text="Akun"/>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="15dp"
    android:src="@drawable/line"/>
<RelativeLayout
    android:layout_width="345dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/tvUsername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="10dp"
        android:text="Username :"/>
    <TextView
        android:id="@+id/tvPassword"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="50dp"
        android:text="Password :"/>
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etusername"
        android:layout_alignBottom="@+id/tvUsername"
        android:layout_alignParentEnd="true" />
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/etpassword"
        android:layout_alignBottom="@+id/tvPassword"
        android:layout_alignParentEnd="true" />
    <Button
        android:id="@+id/btEditAkun"
        android:text="Edit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_gravity="right"
        android:layout_below="@+id/etpassword"/>
</RelativeLayout>
</LinearLayout>

if i click edit button the button save and cancel will appear.. please help me to make the code

  • 写回答

1条回答 默认 最新

  • doujiang1832 2016-07-19 04:41
    关注

    This is sample php code for inserting values into database..

    <?php
        $host='127.0.0.1';
        $uname='root';
        $pwd='password';
        $db="android";
    
        $con = mysql_connect($host,$uname,$pwd) or die("connection failed");
        mysql_select_db($db,$con) or die("db selection failed");
    
        $wmail=$_REQUEST['email'];
        $password=$_REQUEST['password'];
    
        $flag['code']=0;
    
        if($r=mysql_query("insert into sample values('$email','$password') ",$con))
        {
            $flag['code']=1;
            echo"hi";
        }
    
        print(json_encode($flag));
        mysql_close($con);
    ?>
    

    and in Android

    private void makeJsonObjReq() {
    
            Map<String, String> postParam= new HashMap<String, String>();
            postParam.put("email", "xyz@gmail.com");
            postParam.put("password", "somepasswordhere");
    
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
            You_Url, new JsonObject(postParam),
            new Response.Listener<JSONObject>() {
    
                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
    
    
                }
            }, new Response.ErrorListener() {
    
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
    
                }
            }) {
    
        /**
         * Passing some request headers
         * */
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
    };
    
    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(jsonObjReq,tag_json_obj);
    
    // Cancelling request
    // ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);       
    }
    

    And also this is just a sample code For you to learn.. I haven't tested the PHP code..Make proper changes to and also add the required params

    Hope this helps

    EDIT : Also please refer this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题