How to update data to Mobile Services - Android (Windows Azure) |
How to update data to Mobile Services - Android (Windows Azure) สรุปวิธีการบันทึก Update แก้ไขข้อมูลบน Table ของ Mobile Services บน Windows Azure ด้วย Android แบบสั้น ๆ ง่าย ๆ
MyMember.java
package com.example.thaicreate;
public class MyMember {
@com.google.gson.annotations.SerializedName("id")
private int mId;
@com.google.gson.annotations.SerializedName("username")
private String mUsername;
@com.google.gson.annotations.SerializedName("password")
private String mPassword;
@com.google.gson.annotations.SerializedName("name")
private String mName;
@com.google.gson.annotations.SerializedName("tel")
private String mTel;
@com.google.gson.annotations.SerializedName("email")
private String mEmail;
public MyMember() {
// empty
}
public MyMember(String username, String password,
String name,String tel,String email) {
this.setUsername(username);
this.setPassword(password);
this.setName(name);
this.setTel(tel);
this.setEmail(email);
}
public final void setId(int id) {
mId = id;
}
public int getId() {
return mId;
}
public final void setUsername(String username) {
mUsername = username;
}
public String getUsername() {
return mUsername;
}
public final void setPassword(String password) {
mPassword = password;
}
public String getPassword() {
return mPassword;
}
public final void setName(String name) {
mName = name;
}
public String getName() {
return mName;
}
public final void setTel(String tel) {
mTel = tel;
}
public String getTel() {
return mTel;
}
public final void setEmail(String email) {
mEmail = email;
}
public String getEmail() {
return mEmail;
}
}
UpdateActivity.java
//*** Update Record ***//
final EditText txtPassword = (EditText)findViewById(R.id.txtPassword);
final EditText txtName = (EditText)findViewById(R.id.txtName);
final EditText txtEmail = (EditText)findViewById(R.id.txtEmail);
final EditText txtTel = (EditText)findViewById(R.id.txtTel);
//** Select Record ***//
mMyMember.where().field("id").eq(id)
.execute(new TableQueryCallback<MyMember>() {
public void onCompleted(List<MyMember> result, int count, Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
MyMember item = result.get(0);
/*** Update Item ***/
item.setPassword(txtPassword.getText().toString());
item.setName(txtName.getText().toString());
item.setEmail(txtEmail.getText().toString());
item.setTel(txtTel.getText().toString());
// Update Record ***/
mMyMember.update(item, new TableOperationCallback<MyMember>() {
public void onCompleted(MyMember entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
Toast.makeText(UpdateActivity.this, "Update Data Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(UpdateActivity.this, "Update Failed!", Toast.LENGTH_SHORT).show();
Log.d("Error : ",exception.getMessage());
}
}
});
} else {
Log.d("Error","Error Load Data from Mobile Service");
}
}
});
Example
Show Case 3 : Update Data (Android and Mobile Services)
Property & Method (Others Related) |
|