Last active
August 2, 2026 06:29
-
-
Save fpopic/fd9fb10b96af5db9ebe8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package hr.fer.ruazosa.hw3; | |
| import android.app.Activity; | |
| import android.os.Bundle; | |
| import android.text.Editable; | |
| import android.text.TextWatcher; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.EditText; | |
| public class LottoChanceCalculatorActivity extends Activity { | |
| private EditText inputMinor; | |
| private EditText inputMajor; | |
| private String errMsg; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_lotto_chance_calculator); | |
| errMsg = LottoChanceCalculatorActivity.this.getResources().getString(R.string.calculator_input_error); | |
| inputMinor = (EditText) findViewById(R.id.calculator_minor); | |
| inputMajor = (EditText) findViewById(R.id.calculator_major); | |
| inputMajor.addTextChangedListener(new TextWatcher() { | |
| @Override | |
| public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| } | |
| @Override | |
| public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| } | |
| @Override | |
| public void afterTextChanged(Editable s) { | |
| String major = inputMajor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| } | |
| } | |
| }); | |
| inputMinor.addTextChangedListener(new TextWatcher() { | |
| @Override | |
| public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| } | |
| @Override | |
| public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| } | |
| @Override | |
| public void afterTextChanged(Editable s) { | |
| String minor = inputMinor.getText().toString(); | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| } | |
| } | |
| }); | |
| Button submit = (Button) findViewById(R.id.calculator_calculate); | |
| submit.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| String major = inputMajor.getText().toString(); | |
| String minor = inputMinor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| } | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| } | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment