[英]Retrieving data from Azure
I created an azure account connected it with a current android application, created a table and added data to this table from within my application.我创建了一个 azure 帐户,将它与当前的 android 应用程序连接起来,创建了一个表并将数据从我的应用程序中添加到该表中。 The text is added into a textbox and one the button is clicked the data is sent to Azure.文本将添加到文本框中,单击按钮后,数据将发送到 Azure。 I want to be able to retrieve this data in the "Text" field in a list.我希望能够在列表的“文本”字段中检索此数据。 Could anyone show me how I would do this.谁能告诉我我将如何做到这一点。
My Code is as fallows我的代码是休闲
MainActivity主要活动
public class MainActivity extends AppCompatActivity {
private MobileServiceClient mClient;
private EditText title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mClient = new MobileServiceClient(
"https://craigsapp.azure-mobile.net/",
"BTkcgnFQvevAdmmRteHCmhHPzdGydq84",
this
);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
public void onClickB(View view) {
title= (EditText) findViewById(R.id.editText);
Item item = new Item();
item.Text = title.getText().toString();
mClient.getTable(Item.class).insert(item, new TableOperationCallback<Item>() {
public void onCompleted(Item entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
} else {
// Insert failed
}
}
});
}
}
Item Activity物品活动
public class Item {
public String Id;
public String Text;
}
For the POJO Class file Item.java
.对于 POJO 类文件Item.java
。
public class Item {
@com.google.gson.annotations.SerializedName("id")
private String id;
@com.google.gson.annotations.SerializedName("text")
private String text;
public Item() {}
public Item(String id, String text) {
this.id = id;
this.text = text
}
// The getter and setter functions for echo property, and the functions `toString` and `equals`
......
}
As reference, there is a similiar sample project GetStartedWithData
, please see https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData/Android/GetStartedWithData/src/com/example/GetStartedWithData .作为参考,有一个类似的示例项目GetStartedWithData
,请参阅https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData/Android/GetStartedWithData/src/com/example/GetStartedWithData 。
For inserting data into mobile service, please refer to the section How to: Insert data into a mobile service
.如需将数据插入移动服务,请参阅How to: Insert data into a mobile service
将数据插入移动服务部分。
To retrieve your data from azure sql database you have to do it through an asynctask or android service and then use a broadcast receiver to get it to a text field.要从 azure sql 数据库中检索您的数据,您必须通过 asynctask 或 android 服务来完成,然后使用广播接收器将其发送到文本字段。 If you still need help comment below.如果您仍然需要帮助,请在下方评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.