我希望能够从用户列表中获取一个parseobject字符串并在另一个活动上显示下摆,但是当我通过intent将它们发送到另一个活动时,不会显示该字符串,但会显示图像uri并且图像显示在活动上,但不显示在字符串上。
ActivityOne
getActivity().setProgressBarIndeterminateVisibility(true);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
query.whereEqualTo(ParseConstants.KEY_RECIPIENT_IDS, ParseUser.getCurrentUser().getObjectId());
query.addDescendingOrder(ParseConstants.KEY_CREATED_AT);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> messages, ParseException e) {
getActivity().setProgressBarIndeterminateVisibility(false);
if (e == null) {
// We found messages!
mMessages = messages;
String[] usernames = new String[mMessages.size()];
int i = 0;
for(ParseObject message : mMessages) {
usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
i++;
}
if (getListView().getAdapter() == null) {
MessageAdapter adapter = new MessageAdapter(
getListView().getContext(),
mMessages);
setListAdapter(adapter);
}
else {
// refill the adapter!
((MessageAdapter)getListView().getAdapter()).refill(mMessages);
}
}
}
});
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ParseObject message = mMessages.get(position);
ParseFile file = message.getParseFile(ParseConstants.KEY_FILE);
String messagetxt= message.getString(ParseConstants.KEY_MESSGAE);
String information = message.getString(ParseConstants.KEY_INFORMATION);
Uri fileUri = Uri.parse(file.getUrl());
// view the image
Intent intent = new Intent(getActivity(), ActivityTwo.class);
intent.setData(fileUri);
intent.putExtra(messagetxt, "message");
intent.putExtra(information, "information");
startActivity(intent);
}
AcivityTwo
Uri imageUri = getIntent().getData();
Picasso.with(this).load(imageUri.toString()).into(image);
String messagestring = getIntent().getStringExtra("message");
String infostring = getIntent().getStringExtra("information");
message.setText(messagestring);
info.setText(infostring);
答案 0 :(得分:1)
你误以为:
intent.putExtra(messagetxt, "message");
intent.putExtra(information, "information");
我认为应该是:
intent.putExtra("message",messagetxt);
intent.putExtra("information", information);
第一个参数是键,第二个参数是键的值。