我有2個按鈕和1個數字段,如果我按下按鈕沒有東西在字段中,它崩潰,所以我想要做的是禁用按鈕,除非數字字段有一些東西,我已經四處尋找答案,但要麼他們不相關,或者我不知道它是如何適合我的代碼,這裏是每個按鈕的兩個onClick函數。由於如何禁用2個按鈕,如果一個數字字段爲空
public void toPounds(View view){
EditText amount = (EditText)findViewById(R.id.amount);
Double omrAmount = Double.parseDouble(amount.getText().toString());
Double gbrAmount = omrAmount * 1.79;
Toast.makeText(getApplicationContext(), "£" + gbrAmount.toString(), Toast.LENGTH_LONG).show();
}
public void toRiyals(View view){
EditText amount = (EditText)findViewById(R.id.amount);
Double gbrAmount = Double.parseDouble(amount.getText().toString());
Double omrAmount = gbrAmount/1.79;
Toast.makeText(getApplicationContext(), omrAmount.toString() + " Riyals", Toast.LENGTH_LONG).show();
}
按下按鈕首先檢查號碼字段不爲空 –