简体   繁体   中英

Designing an Android calculator using eclipse

i need some insight to an issue.i have designed an android calculator using eclipse. Nothing fancy and not too complicated. If i perform an operation, when i click the equals to button, the answer pops up, no problems. But if i want to carry out another calculation, if i click another number, it is added to the previous result rather than the display being cleared for the new number. I have tried some stuffs but i could not get it right.

My question, how to clear the display after a calculation, on the new number click.

Edit from comments:

This is a little snippet;

@Override public void onClick(View view) { 
   Editable window = value.getText(); 
   switch (view.getId()) { 
     case R.id.button1:
          isResult = false; 
          window.append("1"); 
          break;    
     case R.id.buttonAdd:
          arithmetic = new AddArithmetic(window.toString());    
          value.setText(""); 
          isResult = false;
          break; 
     case R.id.buttonEquals: 
          String result = arithmetic.calculate(window.toString()); 
          value.setText(result); 
          isResult = true;  
          break; 
   } 

still doesnt clear the display

I recommend having a boolean that is set to true when you hit the equals button. Other buttons would check the boolean and if it's true, clear the textview and set the boolean back to false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM