create a common function for getting the displayed number

This commit is contained in:
tibbi 2015-12-24 16:48:44 +01:00
parent 576520dc3a
commit 0c1f8257c9
1 changed files with 7 additions and 3 deletions

View File

@ -22,7 +22,7 @@ public class MainActivity extends AppCompatActivity {
}
private void addDigit(int number) {
final String currentValue = result.getText().toString();
final String currentValue = getDisplayedNumber();
final String newValue = getFormattedValue(currentValue + number);
result.setText(newValue);
}
@ -41,9 +41,13 @@ public class MainActivity extends AppCompatActivity {
}
}
private String getDisplayedNumber() {
return result.getText().toString();
}
@OnClick(R.id.btn_decimal)
public void decimalClicked() {
String value = result.getText().toString();
String value = getDisplayedNumber();
if (!value.contains("."))
value += ".";
result.setText(value);
@ -51,7 +55,7 @@ public class MainActivity extends AppCompatActivity {
@OnClick(R.id.btn_0)
public void zeroClicked() {
String value = result.getText().toString();
String value = getDisplayedNumber();
if (!value.isEmpty() && !value.equals("0"))
value += "0";
result.setText(value);