【发布时间】:2016-08-18 09:07:54
【问题描述】:
这是目前的数学部分,我为每个文本视图元素设置了一个,它计算得很好,我需要的是所有文本视图中的数字在总数达到 510 时停止计数,并且所有其他人在达到 252 时停止计数
当总数达到 510 和/或单个值达到 252 时,我想要一个显示“已达到最高数字”或类似内容的吐司
如果有人不知道,这就是 Java,它在 android studio 中
private View.OnClickListener hpListener = new View.OnClickListener() {
public void onClick(View view) {
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.evval);
// TextView element
TextView HPtx = (TextView) findViewById(R.id.hpval);
TextView atttx = (TextView) findViewById(R.id.attval);
TextView deftx = (TextView) findViewById(R.id.defval);
TextView satx = (TextView) findViewById(R.id.saval);
TextView sdtx = (TextView) findViewById(R.id.sdval);
TextView spdtx = (TextView) findViewById(R.id.spdval);
TextView totaltx = (TextView) findViewById(R.id.totalval);
// Ev values
int add = Integer.parseInt(spinner.getSelectedItem().toString());
// Calculation
int HP = Integer.parseInt(HPtx.getText().toString());
int att = Integer.parseInt(atttx.getText().toString());
int def = Integer.parseInt(deftx.getText().toString());
int sa = Integer.parseInt(satx.getText().toString());
int sd = Integer.parseInt(sdtx.getText().toString());
int spd = Integer.parseInt(spdtx.getText().toString());
int hptotal = HP + add;
int total = hptotal + att + def + sa + sd + spd;
// Value calculations
DecimalFormat addHPFormat = new DecimalFormat("000");
DecimalFormat addtotalFormat = new DecimalFormat("000");
HPtx.setText(addHPFormat.format(hptotal));
totaltx.setText(addtotalFormat.format(total));
}
};
【问题讨论】:
-
欢迎来到 Stack Overflow!能否在您努力解决问题的同时,在内容中提供更好的标题和更详细的信息?
标签: java android textview listener