How to delete data in Mobile Services - Android (Windows Azure)
How to delete data in Mobile Services - Android (Windows Azure) สรุปวิธีการลบ Delete ข้อมูลบน 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;
}
}
MainActivity.java
//** Select Record ***//
mMyMember.where().field("id").eq(currentItem.getId())
.execute(new TableQueryCallback<MyMember>() {
public void onCompleted(List<MyMember> result, int count, Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
MyMember item = result.get(0);
// Delete Record ***/
mMyMember.delete(item, new TableDeleteCallback() {
public void onCompleted(Exception exception,
ServiceFilterResponse response) {
if(exception == null){
Toast.makeText(MainActivity.this, "Delete Data Successfully", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, "Delete Failed!", Toast.LENGTH_SHORT).show();
Log.d("Error : ",exception.getMessage());
}
}
});
Example
Show Case 4 : Delete Data (Android and Mobile Services)