Skip to content

Commit

Permalink
Логика MainActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
lr1ne committed Feb 23, 2024
1 parent e3df8b1 commit 83d6838
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/lori/medcalc/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MainActivity extends AppCompatActivity {
TextView operationField;
Double operand = null;
String lastOperation = "=";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -27,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {

findViewById(R.id.button_plus).setOnClickListener((view)->onOperationClick("+"));
findViewById(R.id.button_enter).setOnClickListener((view)->onOperationClick("="));
findViewById(R.id.button_delete).setOnClickListener((view) -> onDeleteClick());

findViewById(R.id.button0).setOnClickListener((view)->onNumberClick("0"));
findViewById(R.id.button1).setOnClickListener((view)->onNumberClick("1"));
Expand All @@ -40,6 +42,15 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.button9).setOnClickListener((view)->onNumberClick("9"));
findViewById(R.id.comma).setOnClickListener((view)->onNumberClick(","));
}

public void onDeleteClick(){
String number = numberField.getText().toString();
if(number.length() > 0){
number = number.substring(0, number.length() - 1);
numberField.setText(number);
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putString("OPERATION", lastOperation);
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.973" />

<Button
android:id="@+id/button_delete"
android:layout_width="69dp"
android:layout_height="68dp"

android:text="@string/delete"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.976"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.35" />

<Button
android:id="@+id/button_enter"
android:layout_width="65dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="button8" translatable="false">8</string>
<string name="button9" translatable="false">9</string>
<string name="button0" translatable="false">0</string>
<string name="delete">Del</string>
<string name="enter">=</string>
<string name="plus">+</string>
<string name="comma">,</string>
Expand Down

0 comments on commit 83d6838

Please sign in to comment.