我希望你能帮助我 我试图从我的解析数据库中提取我的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
}
}
});
答案 0 :(得分:2)
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>()