- Forum posts: 5
Oct 19, 2015, 8:39:49 PM via Website
Oct 19, 2015 8:39:49 PM via Website
I am trying this features where a user can create questionnaire send it to another user's inbox and as a user click on the inbox message the data will be presented in another Activity as TextView. In other words, I am trying to input data as edit text in one view, save it in parse and pass to another Activity retrieve that data from Parse database in a text view. So far I was able to do everything but I do not know why it is not working? I am not able to display the data or retrieve it in VoteAnswer Activity. Illustration of code is below:
I have been struggling with this for a week. Please help
VoteActivity below as it was success:
Intent intent = this.getIntent();
mainText = (EditText) findViewById(R.id.questionVote);
mTextOne = (EditText) findViewById(R.id.choiceOne);
mTextTwo = (EditText) findViewById(R.id.choiceTwo);
mTextThree = (EditText) findViewById(R.id.choiceThree);
mButton =(Button) findViewById(R.id.createQ);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postmaintText = mainText.getText().toString();
posttextOne = mTextOne.getText().toString();
posttextTwo = mTextTwo.getText().toString();
posttextThree = mTextThree.getText().toString();
postmaintText.trim();
posttextOne.trim();
posttextTwo.trim();
posttextThree.trim();
if (postmaintText.isEmpty() || posttextOne.isEmpty() || posttextTwo.isEmpty()|| posttextThree.isEmpty())
{
AlertDialog.Builder builder = new AlertDialog.Builder(VoteActivity.this);
builder.setMessage(R.string.voteMessage)
.setTitle(R.string.vote_error_title)
.setPositiveButton(android.R.string.ok,null);
AlertDialog dialog = builder.create();
dialog.show();
}
else
{
final ParseObject post = new ParseObject("Messages");
post.put("questionare", postmaintText);
post.put("optionOne", posttextOne);
post.put("optionTwo", posttextTwo);
post.put("optionThree", posttextThree);
post.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e==null) {
// questioner posted successfully
Intent intent = new Intent(VoteActivity.this, recipientsActivity.class);
vote = new Vote (post.getObjectId(), postmaintText, posttextOne, posttextTwo,posttextThree);
String mainTextt = mainText.getText().toString();
String optionOnee = mTextOne.getText().toString();
String optionTwoo= mTextTwo.getText().toString();
String optionThree = mTextThree.getText().toString();
// below is the intent where the list of recipents will be displayed for the user, that is where the app crashes
intent.putExtra(parseConstants.MAIN_QUESTIONRARE, mainTextt);
intent.putExtra(parseConstants.OPTION_ONE, optionOnee);
intent.putExtra(parseConstants.OPTION_TWO, optionTwoo);
intent.putExtra(parseConstants.OPTION_THREE, optionThree);
intent.putExtra(parseConstants.KEY_FILE_TYPE, parseConstants.TYPE_QUESTIONARE);
Toast.makeText(getApplication(), "Sent", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Failed to post", Toast.LENGTH_SHORT).show();
}
It directs to recipients and to inbox fragments from there
else if (messageType.equals(parseConstants.TYPE_QUESTIONARE)) {
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Intent intent = new Intent(getActivity(), VoteAnswer.class);
startActivity(intent);
}
Finally, from inbox it goes to VoteAnswer.Activity here is the part I am not able to display the data into textview
public class VoteAnswer extends ActionBarActivity {
protected TextView questionare ;
protected TextView mOne ;
protected TextView mTwo ;
protected TextView mThree ;
private String question;
private String mO;
private String mT;
private String mH;
private List<Vote> mVotes;
String obj;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vote_answer);
questionare = (TextView) findViewById(R.id.mainQ);
mOne = (TextView) findViewById(R.id.optionO);
mTwo = (TextView) findViewById(R.id.optionTW);
mThree = (TextView) findViewById(R.id.optionTH);
getDetails();
Intent i = getIntent();
// obj = i.getStringExtra("questionare");
// getDetails(obj);
}
private void getDetails () {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages");
query.whereEqualTo("objectId",ParseUser.getCurrentUser().getObjectId());
query.findInBackground( new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e==null) {
for (int i = 0; i <objects.size(); i ++)
{
questionare.setText(objects.get(i).getString("questionare"));
mOne.setText(objects.get(i).getString("optionOne"));
mTwo.setText(objects.get(i).getString("optionTwo"));
mThree.setText(objects.get(i).getString("optionThree"));
}
//question = objects.toString("questionare");
//mO = objects.toString("optionOne");
// mT = objects.toString("optionTwo");
// mH = objects.toString("optionThree");
//addData();
}
else
{
e.printStackTrace();
}
}
});
}
Thanks in advance. I would really love some inputs as I have been struggling with this issue for a week. I do not know what I am missing? I read parse documentation but nothing
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.