• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Querying data from my saved parse database in textview

xmagedo

Lurker
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:

VoteActivity below as it was success:

Java:
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

Java:
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

Java:
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. Please, help with any hint or guidance. I have been really struggling with this issue for a week now
 
Last edited:
Please format the code correctly. It's very hard to read. Thanks.
 
Thanks it's a bit better :)

If you want to pass data from one Activity to another, I personally would not do it the way you have. The way I've done it, which doesn't involve read/writes to the database, is to use a Parcelable object. This allows your data to be serialized and de-serialized, in order to pass it between Activities.

http://developer.android.com/reference/android/os/Parcelable.html

There are loads of tutorials and examples explaining how to do this. e.g.

http://shri.blog.kraya.co.uk/2010/0...-between-activities-using-parcelable-classes/
 
Well, the thing is most of my code is connected with parse database
I am trying to retrieve query of a row, I tried multiple ways but it did not work. If there is way, that will be great. Otherwise, I will try your way
 
Sorry I can't really be of much assistance with Parse as I've not used it myself. However if you're having difficulties it might be that the best way forward is to use Parcelable objects as I described above, which is the standard mechanism for passing data between activities.
 
Back
Top Bottom