一切都很好,但我只是希望我的应用程序检查EditText是否为空,如果它为空则显示一条消息,如果没有则应继续使用以下代码。 任何帮助将不胜感激
public void guessNumber(View view) {
EditText guess = findViewById(R.id.guessText);
int guessnumber = Integer.parseInt(guess.getText().toString());
if(guessnumber>randomnumber) {
makeToast("Lower");
} else if(guessnumber<randomnumber) {
makeToast("Higher");
} else if(guessnumber==randomnumber) {
makeToast("You go me ! Try Again");
Random random = new Random();
randomnumber = random.nextInt(20)+1;
} else {
makeToast("Enter Something First");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random random = new Random();
randomnumber = random.nextInt(20)+1;
}
答案 0 :(得分:0)
使用TextUtils.isEmpty()
(See doc):
if(TextUtils.isEmpty(guess.getText())){
// display message
}else{
guessNumber();
}