繁体   English   中英

从解析服务器检索数据

[英]Retrieving data from parse server

我能够将字符串数组检索到列表视图中,但是当我尝试获取存储在解析的“ newStatus”列中的信息并将其放入新的活动“ StatusDetailView”中时,什么也没发生。
任何帮助都是有益的。 我提供的代码来自udemy教程,我无法联系到讲师。

在主页列表上单击某行时,该行中的文本显示在另一个活动“ StatusDetailView”中

** OnListItemClick **

StatusDetailView.java:

public class StatusDetailView extends Activity {

String objectId;
protected TextView mStatus;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_status_detail_view);

    // initialize
    mStatus = (TextView) findViewById(R.id.statusDetailView);

    // Get the intent that started the activity
    Intent intent = getIntent();
    objectId = intent.getStringExtra("objectID"); // matches key in HomePageActivity

    // query data from parse
    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");

    // Retrieve the object by id
    query.getInBackground("objectId", new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject parseObject, ParseException e) {
            if (e == null) {
                // Success we have a status
                String userStatus = parseObject.getString("newStatus"); // column
                mStatus.setText(userStatus);

            } else {
                // there was an error, advise user
                AlertDialog.Builder builder = new AlertDialog.Builder(StatusDetailView.this);
                builder.setMessage(e.getMessage());
                builder.setTitle("Sorry");
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // close the dialog
                        dialog.dismiss();
                    }
                });

                AlertDialog dialog = builder.create();
                dialog.show();
            }
        }
    });

当我运行应用程序并选择一行时,它带我进入StatusDetailView活动,但出现错误,但列表显示8行:

错误

状态清单

这里:

query.getInBackground("objectId", new GetCallback<ParseObject>() {
                       ^^^^^^^
 ..
}

objectId字符串作为id传递,而不是使用intent.getStringExtra初始化的objectId String的值。

要使其工作,请将其更改为:

query.getInBackground(objectId, new GetCallback<ParseObject>() {

 ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM