从Azure检索数据

时间:2016-03-23 15:45:37

标签: java android azure android-activity

我创建了一个azure帐户,将其与当前的Android应用程序连接,创建了一个表,并从我的应用程序中向该表添加了数据。文本被添加到文本框中,单击该按钮将数据发送到Azure。我希望能够在" Text"中检索这些数据。列表中的字段。任何人都可以告诉我如何做到这一点。

我的代码就像休耕一样

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
                }
            }
        });
    }

}

项目活动

public class Item {
    public String Id;
    public String Text;

}

2 个答案:

答案 0 :(得分:0)

对于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`
    ......
}

作为参考,有一个类似的示例项目GetStartedWithData,请参阅https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData/Android/GetStartedWithData/src/com/example/GetStartedWithData

要将数据插入移动服务,请参阅How to: Insert data into a mobile service

部分

答案 1 :(得分:0)

要从azure sql数据库中检索数据,您必须通过asynctask或android服务进行检索,然后使用广播接收器将其转换为文本字段。 如果您仍需要以下帮助评论。

相关问题