Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/src/main/java/com/exuberant/calci/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class HomeActivity extends AppCompatActivity implements View.OnClickListener {

private String currentNumber = "", totalCalculation = "";
private String currentNumber = "0", totalCalculation = "0";
private TextView totalCalculationTextView, currentAnswerTextView;

@Override
Expand Down Expand Up @@ -56,8 +56,8 @@ public void onClick(View view) {

//Handling clear button
case R.id.btn_clear:
currentNumber = "";
totalCalculation = "";
currentNumber = "0";
totalCalculation = "0";
break;

//Handle calculation
Expand All @@ -68,7 +68,11 @@ public void onClick(View view) {

//Handle other numerical button clicks
default:
currentNumber += button.getText().toString();
if(!currentNumber.equals("0")){
currentNumber += button.getText().toString();
}else{
currentNumber = button.getText().toString();
}
}
updateDisplay();
}
Expand All @@ -81,7 +85,7 @@ private void updateDisplay(){
private void handleOperatorClick(String operator){
if (!(currentNumber.equals("") || currentNumber.length() == 0)) {
totalCalculation += currentNumber + operator;
currentNumber = "";
currentNumber = "0";
} else {
totalCalculation = totalCalculation.substring(0, totalCalculation.length() - 1);
totalCalculation += operator;
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/res/layout/content_answer_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:gravity="end"
android:textSize="24sp"
android:textSize="18sp"
android:text="@string/total_calculation"
android:textColor="#757575"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Expand All @@ -23,9 +22,8 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:gravity="end"
android:textSize="32sp"
android:textSize="24sp"
android:text="@string/current_calculation"
android:textColor="#757575"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Expand Down