[英]Get Preloaded Data from Azure Mobile Service Android
I want to get all the preloaded datas available on my Windows Azure Mobile Service. 我想在Windows Azure移动服务上获得所有可用的预加载数据。
Let's just say I have a Table named RV_RoadData and inside the Table, there is a Column for StudentIDs as Integer and Text as String. 假设我有一个名为RV_RoadData的表,并且该表中有一个学生ID列(作为整数)和文本(字符串)。 There are 50 Values loaded so far.
到目前为止,已加载50个值。
I just want to save those values in my ArrayList and then use for future references. 我只想将这些值保存在ArrayList中,然后用于将来的引用。 This is what I tried:
这是我尝试的:
public class MainActivity extends ActionBarActivity {
TextView textView;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fechFromAzure();
}
//this is the only method talking to azure.
//here, no threads/asynctasks are used. So, fetching operation should not take more
//than 5 seconds. Otherwise, app will freeze.
private void fechFromAzure(){
try {
//initialize the mobile service
MobileServiceClient mClient = new MobileServiceClient(
"https://******.azure-mobile.net/",
"*******************************",
this
);
//get the todo-item table
MobileServiceTable<RV_RoadData> RV_RoadData_Table = mClient.getTable(RV_RoadData.class);
//select all items from todo-item
List<RV_RoadData> itemList = RV_RoadData_Table.where().execute().get();
//set text of first and only one todo-item to textview
textView.setText(itemList.get(0).Text);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
class RV_RoadData {
public String Id;
public String Text;
}
}
But is seems to give me unwanted Exception. 但是似乎给了我不必要的异常。 I really don't know where I am doing wrong.
我真的不知道我在哪里做错了。 Please help to solve this problem.
请帮助解决此问题。 Thanks.
谢谢。
Try following the pattern in this tutorial, which uses an adapter to store a list of data. 尝试遵循本教程中的模式,该模式使用适配器来存储数据列表。
https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-data/ https://azure.microsoft.com/zh-CN/documentation/articles/mobile-services-android-get-started-data/
It also returns a MobileServicesList instead of a List. 它还返回MobileServicesList而不是List。 The data in its database is also very similar to yours, so it should be very easy to adapt it.
数据库中的数据也与您的数据库非常相似,因此应该很容易进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.