For a personal project I am making a calculator that can parse a regular expression from a user inputted string.
My main problem right now is that if the user inputs some input, say 1 + 2 , then rotates the device, although I have managed to get my program to preserve the 1 + 2 after rotation, any additional inputs from the user will wipe it out and replace it entirely with the next input. So if I inputted 1 + 2, then rotated the device, then inputted + 4, the device would read + 4 instead of 1 + 2 + 4 like I was expecting.
Here is my code so far, thank you for your help in advance:
public class MyCalculator extends Activity {
String displayStr = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_calculator);
Button btnClear = (Button) findViewById(R.id.btnClear);
btnClear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayStr = "";
TextView et= (TextView) findViewById(R.id.display);
et.setText(displayStr);
}
});
}
public void enterDigit(View view){
TextView et = (TextView) findViewById(R.id.display);
Button button = (Button)view;
if(et.getText().toString().compareTo("Unable to Parse") == 0){
displayStr = (String) button.getText();
}
else{
displayStr += button.getText();
}
et.setText(displayStr);
}
public void enterOperation(View view){
TextView et = (TextView) findViewById(R.id.display);
Button button = (Button)view;
if(et.getText().toString().compareTo("Unable to Parse") == 0){
displayStr = (String) button.getText();
}
else{
displayStr += " " + button.getText() + " ";
}
et.setText(displayStr);
}
public void enterClick(View v){ //TBD error checking
String s = "";
TextView et = (TextView) findViewById(R.id.display);
s = et.getText().toString();
s = TestParser.parse(s);
et.setText(s);
displayStr= "";
}
}