从解析服务器

时间:2016-06-09 04:23:57

标签: android parse-platform

我能够将字符串数组检索到列表视图中,但是当我尝试获取存储在parse的“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行:

error

list of statuses

1 个答案:

答案 0 :(得分:1)

下面:

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

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

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

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

 ...
}