如果editText留为空白,我的应用程序将继续崩溃。如果单击“添加”按钮时不存在任何内容,则我需要使用这些空格来假定条目为“ 0”(零)。
Button addBtn = (Button) findViewById(R.id.FHAddBtn);
addBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final EditText FHEnter5RingEditText = (EditText) findViewById(R.id.FHEnter5RingEditText);
final EditText FHEnter4RingEditText = (EditText) findViewById(R.id.FHEnter4RingEditText);
final EditText FHEnter3RingEditText = (EditText) findViewById(R.id.FHEnter3RingEditText);
final EditText FHEnter2RingEditText = (EditText) findViewById(R.id.FHEnter2RingEditText);
final EditText FHEnterMissesEditText = (EditText) findViewById(R.id.FHEnterMissesEditText);
final TextView FHScoreTextView = (TextView) findViewById(R.id.FHScoreTextView);
final TextView FHRoundCountTextView = (TextView) findViewById(R.id.FHRoundCountTextView);
int FHring5 = Integer.parseInt(FHEnter5RingEditText.getText().toString());
int FHring4 = Integer.parseInt(FHEnter4RingEditText.getText().toString());
int FHring3 = Integer.parseInt(FHEnter3RingEditText.getText().toString());
int FHring2 = Integer.parseInt(FHEnter2RingEditText.getText().toString());
int FHring0 = Integer.parseInt(FHEnterMissesEditText.getText().toString());
int FHroundCount = FHring5 + FHring4 + FHring3 + FHring2 + FHring0;
int FHresult = (FHring5 * 5) + (FHring4 * 4) + (FHring3 * 3) + (FHring2 * 2);
FHRoundCountTextView.setText(FHroundCount + "");
FHScoreTextView.setText(FHresult + "");
if (FHresult < 120) {
FHScoreTextView.setTextColor(Color.RED);
} else if (FHresult > 150) {
FHScoreTextView.setTextColor(Color.RED);
}else{
FHScoreTextView.setTextColor(Color.GREEN);
}
if (FHroundCount > 30) {
FHRoundCountTextView.setTextColor(Color.RED);
}else{
FHRoundCountTextView.setTextColor(Color.BLACK);
}