2014-12-28 85 views
0

我希望你能幫助我與這些 我想從我的解析數據庫中提取信息爲我的android應用程序(只是一個查看應用程序) 基本上我想要做的是我去選擇第一個條件:當前解析用戶=當前用戶(來自數據庫) 第二個條件:旋轉器上的選定項目(旋轉月)=月(第二個條件)來自數據庫) 第三種情況:微調器上的選定項二(旋轉年)=年(來自數據庫)安卓解析查詢與mutltiple條件

然後它會給我需要每個文本視圖中的數據(我可以只用一個條件要做到這一點,但我需要指定它分爲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 
          } 
        } 

        }); 

回答

0

所以顯然我得到了答案,我需要 我省略了前分析查詢我用 插入btnView 的上點擊功能內的兩個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>()