我是 azure 新手,但我知道某些事情,例如如何检索数据并将数据存储到 azure,为此我遵循了 azure 官方文档。
链接在这里 - https://azure.microsoft.com/en-in/documentation/articles/mobile-services-android-get-started-data/
但问题是,本教程仅展示如何使用适配器和列表从 azure 检索和使用数据。 我想知道,如何从 azure 移动服务检索单个值以及如何在 android 中使用它。
请为我提供后端代码(如果有的话)和java代码。提前致谢
最佳答案
我已经解决了。无需创建自定义 API。
只需遵循基础知识即可,这是代码:-
final String[] design = new String[1];
private MobileServiceTable<User> mUser;
mUser = mClient.getTable(User.class);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
final MobileServiceList<User> result =
mUser.where().field("name").eq(x).execute().get();
for (User item : result) {
// Log.i(TAG, "Read object with ID " + item.id);
desig[0] = item.getDesignation(); //getDesignation() is a function in User class ie- they are getters and setters
Log.v("FINALLY DESIGNATION IS", desig[0]);
}
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
designation.setText(desig[0]);
}
}.execute();
不要忘记为序列化
等创建一个User
类。您还应该定义数组。
如果您发现它不起作用,请随意写。
编辑:-
design[0]
是一个大小为 1 的数组。
eq(x)
等于 x
,其中,x
变量包含我想要从数据库 (azure) 指定的用户名。
关于Java - 如何从 Android 中的 azure 移动服务检索和使用单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31364134/