1)Tableの構造と合うclassを用意します。
package com.example.azuretest;
public class TokutenItem {
@com.google.gson.annotations.SerializedName("id")
private int mId;
@com.google.gson.annotations.SerializedName("venusId")
private String mVenusId;
@com.google.gson.annotations.SerializedName("pointUp")
private float mPointUp;
@com.google.gson.annotations.SerializedName("pricedown")
private int mPriceDown;
@com.google.gson.annotations.SerializedName("cardId")
private int mCardId;
public TokutenItem(String venusId, float pointUp, int priceDown, int cardId) {
//this.setId(id); idは自動的に付与され、set不可のようです
this.setVenusId(venusId);
this.setPointUp(pointUp);
this.setPriceDown(priceDown);
this.setCardId(cardId);
}
public int getId() {
return mId;
}
public String getVenusId() {
return mVenusId;
}
public float getPointUp() {
return mPointUp;
}
public int getPriceDown() {
return mPriceDown;
}
public int getCardId() {
return mCardId;
}
public final void setId(int id) {
mId = id;
}
public final void setVenusId(String venusId) {
mVenusId = venusId;
}
public final void setPointUp(float pointUp) {
mPointUp = pointUp;
}
public final void setPriceDown(int priceDown) {
mPriceDown = priceDown;
}
public final void setCardId(int cardId) {
mCardId = cardId;
}
}
2)MobileServiveClientの設定、そしてMobileServiceTableの設定
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"https://xxxxxxx.azure-mobile.net/",
"keyforAzuraMobileService",
this);
// Get the Mobile Service Table instance to use
mTokutenTable = mClient.getTable(TokutenItem.class);
} catch (MalformedURLException e) {
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
// 挿入したいItem項目をclassに入れる、idの設定は不可
TokutenItem mTokutenItem = new TokutenItem("4e25173e091a817e3dd67300",2,300,3);
mTokutenTable.insert(mTokutenItem, new TableOperationCallback<TokutenItem>() {
public void onCompleted(TokutenItem entity,
Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
//Log.i(TAG, "Read object with ID " + entity.id);
} else {
createAndShowDialog(exception, "Error");
}
}
});
getTableは、classの構造に合わせて、SQLの列を追加してくれます。
3) Permissionの追加を忘れず
<uses-permission android:name="android.permission.INTERNET" />
0 件のコメント:
コメントを投稿