因此Azure的吐爲我插入到一個活動下面的代碼(Android的工作室是我使用的是什麼)檢查Azure的連接數據庫的onClick進行登錄
以下行添加到包含的.java文件的頂部你的發射活動:
import com.microsoft.windowsazure.mobileservices.*;
您的活動中,添加一個私有變量
private MobileServiceClient mClient;
添加以下代碼活動的onCreate方法:
mClient = new MobileServiceClient("https://pbbingo.azurewebsites.net", this);
到項目::
public class ToDoItem{ public String id; public String Text;}
添加一個樣本物品類在您定義移動客戶端相同的活動,添加以下代碼:
ToDoItem item = new ToDoItem();
item.Text = "Don't text and drive";
mClient.getTable(ToDoItem.class).insert(item, new TableOperationCallback<item>(){
public void onCompleted(ToDoItem entity, Exception exception, ServiceFilter response)
{
if(exception == null){
//Insert Succeeded
} else {
//Insert Failed
}
}});
我的目標是創建一個登錄頁面。我明白,上面提到的可能更多地考慮了ToList。我只想今天獲得正確的語法。我想這個問題是我基本的班級結構。我在創建時創建了一個OnClick Listener,它從我的佈局中的按鈕獲取ID。我不需要檢查數據庫中的任何內容,直到按鈕被實際單擊以登錄或註冊。
public class LoginClass extends AppCompatActivity{
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.MyLoginLayout);
MobileServiceClient mClient = null;
try {
mClient = new MobileServiceClient ("myAzureWebsite", "AzureKey", this);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Button Attempt = (Button) findViewById (R.id.mySubmitButton);
final MobileServiceClient finalMClient = mClient; // finalized so I can use it later.
Attempt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
final View thisView = v;
final MyToDoItemClass item = new MyToDoItemClass();
In MyToDoItemClass I have two variables (Both String) Just left over from
the example of a ToDoList (they are String ID and String Text)
item.Text = "Filler";
item.ID = "Fill";
finalMClient.getTable(MyToDoItemClass.class).insert(new Table OperationCallback<item>() { //<--- I'm getting an error that the variable, item
is from an unknown class...
public void onCompleted (Item entity, Exception exception, ServiceFilterResponse response){
if(exception == null) {
Intent i = new Intent (LoginClass.this, MainActivity.class);
startActivity(i);
}else{
Toast.makeText(thisView.getContext(), "Failed", Toast.LENGTH_LONG).show();
}}
});
}
});
}}
問題是與該TableOperationCallback是說,從MyToDoItemClass類項目是從一個未知的類。
非常感謝。我認爲提供的方法我們是自給自足的(只要包含導入和正確的lib文件夾),但我現在將它們正確地放在一起。 –