Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mImieET=findViewById(R.id.imieEditText);
- mNazwiskoET=findViewById(R.id.nazwiskoEditText);
- mLiczbsOcenET=findViewById(R.id.liczbaOcenEditText);
- mOcenyB=findViewById(R.id.ocenyButton);
- mImieET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if (!hasFocus){
- String imie=mImieET.getText().toString();
- if (imie==null || imie.isEmpty())
- mImieET.setError("Pole Imię nie może być puste");
- }
- }
- });
- mNazwiskoET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if (!hasFocus){
- String nazwisko=mNazwiskoET.getText().toString();
- if (nazwisko==null || nazwisko.isEmpty())
- mNazwiskoET.setError("Pole Nazwisko nie może być puste");
- }
- }
- });
- mLiczbsOcenET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if (!hasFocus){
- String liczbaOcen=mLiczbsOcenET.getText().toString();
- if (liczbaOcen==null || liczbaOcen.isEmpty())
- mLiczbsOcenET.setError("Pole Liczba ocen nie może być puste");
- else if (Integer.valueOf(liczbaOcen) < 5 || Integer.valueOf(liczbaOcen) > 15) {
- mLiczbsOcenET.setError("Musisz podać liczbę z przedziału 5-15");
- }
- }
- }
- });
- public void buttonVisibility() {
- if (imie == null || imie.isEmpty() || nazwisko == null || nazwisko.isEmpty() || liczbaOcen == null || liczbaOcen.isEmpty() || Integer.valueOf(liczbaOcen) < 5 || Integer.valueOf(liczbaOcen) > 15)
- mOcenyB.setVisibility(View.INVISIBLE);
- else
- mOcenyB.setVisibility(View.VISIBLE);
- }
- }
- private EditText mImieET;
- private EditText mNazwiskoET;
- private EditText mLiczbsOcenET;
- private Button mOcenyB;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement