Skip to content

Commit

Permalink
Fixed issue IEEE-VIT#6 - Crash on pressing operator buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
sivansundar committed Oct 7, 2019
1 parent 77d981e commit 3297fd0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/exuberant/calci/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -11,7 +12,9 @@

public class HomeActivity extends AppCompatActivity implements View.OnClickListener {

private static final String TAG = "HomeActivity";
private String currentNumber = "", totalCalculation = "";

private TextView totalCalculationTextView, currentAnswerTextView;

@Override
Expand Down Expand Up @@ -66,6 +69,7 @@ public void onClick(View view) {
calculateAnswer();
break;


//Handle other numerical button clicks
default:
currentNumber += button.getText().toString();
Expand All @@ -83,8 +87,12 @@ private void handleOperatorClick(String operator){
totalCalculation += currentNumber + operator;
currentNumber = "";
} else {
totalCalculation = totalCalculation.substring(0, totalCalculation.length() - 1);
totalCalculation += operator;
if (!totalCalculation.isEmpty()) {

totalCalculation = totalCalculation.substring(0, totalCalculation.length() - 1);
totalCalculation += operator;

}
}
}

Expand All @@ -107,6 +115,8 @@ private double div(double a, double b){
private void calculateAnswer(){
//Use totalCalculation string to get final answer and display it
double answer = 0.0;
currentNumber = "";
Log.d(TAG, "calculateAnswer: totalCalculationString : " + totalCalculation);
updateDisplay();
}
}

0 comments on commit 3297fd0

Please sign in to comment.