Search code examples
androidparse-platform

android Parse.com get specific data


here is my screenshot

http://i.imgur.com/JbllLKO.png

in my activity.java

    btnSearchemail = (Button) findViewById(R.id.btnSearchemail);
    txtSearchemail = (EditText) findViewById(R.id.txtSearchemail);

    Searchemail = txtSearchemail.getText().toString();

    txtFname = (TextView) findViewById(R.id.txtFname);
    txtLname = (TextView) findViewById(R.id.txtLname);



    btnSearchemail.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            final ParseQuery<ParseObject> query = ParseQuery
                    .getQuery("account");
            query.whereEqualTo("email", Searchemail);
            query.findInBackground(new FindCallback<ParseObject>() {
                public void done(List<ParseObject> results, ParseException e) {
                    if (e == null) {
                        // results contains a list of all the emails found

                        for (ParseObject x : results) {
                            String fname = x.getString("firstName");
                            String lname = x.getString("lastName");


                        }
                        // i replace it here this is edited/updated
                        txtFname.setText(fname);
                        txtLname.setText(lname);

                    } else {
                        // error
                        Toast.makeText(Sample.this.getApplicationContext(),
                                "error", Toast.LENGTH_LONG).show();
                    }
                }
            });

        }
    });

I want to retrieve specific data according to email that I put in my edittext. nothing happens again when i click the button.


Solution

  • You'd need to call a query. Note this function is asynchronous. Documentation can be found here.

    ParseQuery<ParseObject> query = ParseQuery.getQuery("account");
    query.whereEqualTo("email", emailsave);
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> results, ParseException e) {
            if (e == null) {
                // results contains a list of all the emails found
                for (ParseObject x : results) {                     
                     String fname = x.getString("firstName");
                     String lname = x.getString("lastName");
                     // Put breakpoint here and see what the variables contain
                     txtFname.setText(fname);
                     txtLname.setText(lanme)
                }
            } else {
                // error
            }
        }
    });