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

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

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)