具有多个条件的Android Parse查询

时间:2014-12-28 13:01:32

标签: android database parse-platform

我希望你能帮助我 我试图从我的解析数据库中提取我的Android应用程序(只是一个查看应用程序)的信息 基本上我想要做的就是选择我的两个微调器并单击视图 点击查看后,它应该查询三个条件

第一个条件:当前解析用户=当前用户(来自数据库) 第二个条件:旋转器上的选定项目(旋转月份)=月份(来自数据库) 第三个条件:旋转器上的选定项目2(旋转年份)=年份(来自数据库)

然后它将为我提供每个文本视图所需的数据(我只能通过一个条件执行此操作,但我需要将其指定为3个条件)

班级名称:工资单 列中的列名称:用户名,月份,年份

我不确定哪种或哪种if语句,开关盒或任何我可以使用的东西,所以我可以适应这三个条件 非常感谢帮助!

    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
                            }
                    }

                    });

1 个答案:

答案 0 :(得分:2)

显然,我得到了我需要的答案 我省略了我使用的第一个解析查询 在btnView的on click函数中插入了两个spinner.selected项 并创建了三线条件查询,有效! 问题是它不适用这三个条件,因为在我的解析数据库年份是数字,在这里我得到它作为一个字符串..

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>()