EditTextが空でTextViewが右のテキストを表示しているのに、EditTextフィールドに数字を書き込んでボタンを押すと、必要なテキストをTextViewで特定のEditText条件に置くボタンを作ろうとしています。 。 入れ子のif文ですか?
public void Guess(View view) {
EditText Spejimas = (EditText) findViewById(R.id.guess);
Tekstas = (TextView) findViewById(R.id.textView3);
if (Spejimas.getText().length() == 0) {
Tekstas.setText("Oops, you forgot to type your guess!");
} else if (Spejimas.getText().length() != 0) {
int Guessas = Integer.parseInt(Spejimas.toString());
if (Guessas == number) {
Tekstas.setText("Congratulations! You got it right!");
} else if (Guessas > number) {
Tekstas.setText("Your number is too high, try again!");
} else if (Guessas < number) {
Tekstas.setText("Your number is too low, try again!");
}
}
}
私はTextViewには言いたい:「!!おめでとうございますあなたは右のそれを得た」、Guessasは数に等しいときに、「あなたの数が多すぎる、もう一度試して!」、Guessasは「数よりも高い場合あなたの数字は低すぎます、もう一度やり直してください! "、ゲッサスが数字よりも低いとき。
EditTextに数字があるときにこのコードブロックをトリガーするボタンを押すと、プログラムがクラッシュします。
'int Guessas = Integer.parseInt(Spejimas.getText());'多分、 –
なぜクラッシュするのですか? logcatを投稿すると、エラーがどこにあるかがわかります。 –