因此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文件夹),但我现在将它们正确地放在一起。 –