Kinji Tohyama
Kinji Tohyama

Reputation: 31

Android Parse Query with mutltiple conditions

I hope you can help me with these I am trying to extract information from my parse database for my android app (just a viewing app) Basically what I want to do is I go select on my two spinners and click view Once I click view it should query on three conditions

1st condition: current parse user = current user (from database) 2nd condition: selected item on spinner one (spin Month) = month (from database) 3rd condition: selected item on spinner two (spin Year) = year (from database)

Then it will give me the data needed for each text view (I was able to do this with just one condition but I need to specify it into 3 conditions)

Class Name: payslip Column Name from class: username, month, year

I'm not sure which or what kind of if statement, switch case, or anything I can use so I can fit these 3 conditions Thanks a bunch for the help!

    a = (Spinner) findViewById(R.id.spinMonth);
ArrayAdapter adapterA = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, month);
a.setAdapter(adapterA);

b = (Spinner) findViewById(R.id.spinYear);
ArrayAdapter adapterB = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, year);
b.setAdapter(adapterB);

  ParseQuery<ParseObject> query = ParseQuery.getQuery("payslip");
    query.whereEqualTo("username",ParseUser.getCurrentUser().getUsername());
    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
      public void done(List<ParseObject> res, ParseException e) {
        if (res == null) {
            Toast.makeText(getApplicationContext(),
                    "Data Retrieved",
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(),
                    "Data Not Retrieved",
                    Toast.LENGTH_LONG).show();
        }
      }
    });

    stringmonth = (String) a.getSelectedItem();
    stringyear = (String) b.getSelectedItem();


    view.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {



                ParseQuery<ParseObject> mainQuery = ParseQuery.getQuery("payslip");
                mainQuery.whereEqualTo("month",stringmonth);
                mainQuery.whereEqualTo("year",stringyear);
                mainQuery.findInBackground(new FindCallback<ParseObject>() {
                    @Override
                    public void done(List<ParseObject> results, ParseException e) {


                        // TODO Auto-generated method stub
                         if (e == null) {

                             for (ParseObject x : results) { 
                                 String name = x.getString("name");
                                 basic = x.getDouble("basicpay");
                                 Double regot = x.getDouble("regot");
                                 Double nightdiff = x.getDouble("nightdiff");
                                 Double sss = x.getDouble("sss");                   
                                 Double hdmf = x.getDouble("hdmf");
                                 Double philhealth = x.getDouble("philhealth");
                                 Double tax = x.getDouble("tax");
                                 Double adjustment = x.getDouble("adjustment");                                                                              

                                 txtName.setText(name);
                                 String stringbasic = Double.toString(basic);
                                 txtBasic.setText(stringbasic);
                                 String stringregot = Double.toString(regot);
                                 txtRegot.setText(stringregot);
                                 String stringnd = Double.toString(nightdiff);
                                 txtND.setText(stringnd);
                                 String stringsss = Double.toString(sss);
                                 txtSSS.setText(stringsss);
                                 String stringhdmf = Double.toString(hdmf);
                                 txtHDMF.setText(stringhdmf);
                                 String stringphilhealth = Double.toString(philhealth);
                                 txtPhilhealth.setText(stringphilhealth);
                                 String stringtax =Double.toString(tax);
                                 txtTax.setText(stringtax);
                                 String stringadjust = Double.toString(adjustment);
                                 txtAdjust.setText(stringadjust);
                                 gross = Double.valueOf(basic)+Double.valueOf(regot)+Double.valueOf(nightdiff);
                                 String stringgross = Double.toString(gross);
                                 txtGross.setText(stringgross);
                                 deduction = Double.valueOf(sss)+Double.valueOf(hdmf)+Double.valueOf(tax)+Double.valueOf(philhealth);
                                 String stringdeduction= Double.toString(deduction);
                                 txtDeductions.setText(stringdeduction);
                                 netpay= gross-deduction;

                                 BigDecimal bd = new BigDecimal(netpay).setScale(2, RoundingMode.HALF_EVEN);
                                 netpay = bd.doubleValue();

                                 String stringnetpay=Double.toString(netpay);
                                 txtNetpay.setText(stringnetpay);

                            }
                         }else {
                                // error
                            }
                    }

                    });

Upvotes: 1

Views: 1212

Answers (1)

Kinji Tohyama
Kinji Tohyama

Reputation: 31

so apparently I got the answer I need I omitted the first parse query I used Inserted the two spinner.selected item inside the on click function of btnView And also created the three line condition query which works! The problem it doesn't apply the three conditions because in my parse database year is number and here I get it as a string..

public void onClick(View arg0) {

stringmonth = (String) a.getSelectedItem();
stringyear = (String) b.getSelectedItem();
numyear = Double.valueOf(stringyear);  

ParseQuery<ParseObject> mainQuery = ParseQuery.getQuery("payslip");
mainQuery.whereEqualTo("username",ParseUser.getCurrentUser().getUsername());
mainQuery.whereEqualTo("month",stringmonth);
mainQuery.whereEqualTo("year",numyear);
mainQuery.findInBackground(new FindCallback<ParseObject>() 

Upvotes: 2

Related Questions