预置时,清除按钮不起作用

时间:2016-10-29 17:49:44

标签: android button calculator

当我点击清除按钮时,它不会清除我的书面数字。有什么问题?

    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
    }
}

1 个答案:

答案 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("")
}