I am able to retrieve the array of strings into a list view but when I try and get the information stored in the "newStatus" column of parse and put it into a new activity "StatusDetailView", nothing comes out. The code I am providing is from a tutorial on Udemy and I am unable to reach the instructor.
When a row is clicked on the homepage list, the text from the row is displayed in another activity "StatusDetailView"
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();
}
}
});
When I do run the app and I select a row, it takes me to the StatusDetailView Activity with an error but the list displays 8 rows:
Here:
query.getInBackground("objectId", new GetCallback<ParseObject>() {
^^^^^^^
..
}
passing objectId
string as id instead of value of objectId
String which is initialized using intent.getStringExtra
.
To get it work change it as:
query.getInBackground(objectId, new GetCallback<ParseObject>() {
...
}