我有六对编辑文本,不是所有的都必须编辑,但至少一对必须编辑。我想要做的是将空的设置为零,这样数学就可以解决,但编辑文本中没有显示 0,所以用户不必继续删除零
我现在得到的并不理想
if (width1.getText().toString().equals("")
|| height1.getText().toString().equals("")
|| width2.getText().toString().equals("")
|| height2.getText().toString().equals("")
|| width3.getText().toString().equals("")
|| height3.getText().toString().equals("")
|| width4.getText().toString().equals("")
|| height4.getText().toString().equals("")
|| width5.getText().toString().equals("")
|| height5.getText().toString().equals("")
|| width6.getText().toString().equals("")
|| height6.getText().toString().equals("")) {
width1.setText("0");
width2.setText("0");
width3.setText("0");
width4.setText("0");
width5.setText("0");
width6.setText("0");
height1.setText("0");
height2.setText("0");
height3.setText("0");
height4.setText("0");
height5.setText("0");
height6.setText("0");
}
calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (width1.getText().toString().equals("0")
|| height1.getText().toString().equals("0")) {
Toast msg = Toast.makeText(getBaseContext(),
"Please enter measurements", Toast.LENGTH_LONG);
msg.show();
}
else {
Intent sender = getIntent();
int result100 = sender.getExtras().getInt("Result100");
int result215 = sender.getExtras().getInt("Result215");
int result325 = sender.getExtras().getInt("Result315");
a = Double.parseDouble(width1.getText().toString());
b = Double.parseDouble(height1.getText().toString());
c = Double.parseDouble(width2.getText().toString());
d = Double.parseDouble(height2.getText().toString());
e = Double.parseDouble(width3.getText().toString());
f = Double.parseDouble(height3.getText().toString());
u = Double.parseDouble(width4.getText().toString());
v = Double.parseDouble(height4.getText().toString());
w = Double.parseDouble(width5.getText().toString());
x = Double.parseDouble(height5.getText().toString());
y = Double.parseDouble(width6.getText().toString());
z = Double.parseDouble(height6.getText().toString());
if (getIntent().hasExtra("Result100")) {
total = (result100) - (a * b) + (c * d) + (e * f)
+ (u * v) + (w * x) + (y * z) * 60;
} else if (getIntent().hasExtra("Result215")) {
total = (result215) - (a * b) + (c * d) + (e * f)
+ (u * v) + (w * x) + (y * z) * 120;
} else if (getIntent().hasExtra("Result315")) {
total = (result325) - (a * b) + (c * d) + (e * f)
+ (u * v) + (w * x) + (y * z) * 180;
}
Intent intent = new Intent(MinusOpes.this,
Wl2Amounts.class);
intent.putExtra("Result", total);
startActivity(intent);
}