当我点击清除按钮时,它不会清除我的书面数字。有什么问题?
calcBtn.setOnClickListener(new View.OnClickListener () {
clearBtn.setOnClickListener(new View.OnClickListener (){
}
} {
@Override
public void onClick(View view) {
try {
float percentege = Float.parseFloat(percentageTxt.getText().toString());
float dec = percentege / 100;
float total = dec * Float.parseFloat(numberTxt.getText().toString());
totalTextWiew.setText(Float.toString(total));
} catch (NumberFormatException nfe) {
totalTextWiew.setText("Error");
if (view==clearBtn);
numberTxt.clear
}
}
答案 0 :(得分:0)
calcBtn.setOnClickListener(new View.OnClickListener () {
@Override public void onClick(View view) {
try {
float percentege = Float.parseFloat(percentageTxt.getText().toString());
float dec = percentege / 100;
float total = dec * Float.parseFloat(numberTxt.getText().toString()); totalTextWiew.setText(Float.toString(total));
} catch (NumberFormatException nfe) {
totalTextWiew.setText("Error");
}
}
}
clearBtn.setOnClickListener(new View.OnClickListener () {
@Override public void onClick(View view) {
//do your clearing thing here
// eg numbertxt.clear
//or numbertxt.setText("")
}