Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. package com.example.myapplication;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15.  
  16. mImieET=findViewById(R.id.imieEditText);
  17. mNazwiskoET=findViewById(R.id.nazwiskoEditText);
  18. mLiczbsOcenET=findViewById(R.id.liczbaOcenEditText);
  19. mOcenyB=findViewById(R.id.ocenyButton);
  20.  
  21. mImieET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  22. @Override
  23. public void onFocusChange(View v, boolean hasFocus) {
  24. if (!hasFocus){
  25. String imie=mImieET.getText().toString();
  26. if (imie==null || imie.isEmpty())
  27. mImieET.setError("Pole Imię nie może być puste");
  28. }
  29. }
  30. });
  31.  
  32. mNazwiskoET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  33. @Override
  34. public void onFocusChange(View v, boolean hasFocus) {
  35. if (!hasFocus){
  36. String nazwisko=mNazwiskoET.getText().toString();
  37. if (nazwisko==null || nazwisko.isEmpty())
  38. mNazwiskoET.setError("Pole Nazwisko nie może być puste");
  39. }
  40. }
  41. });
  42.  
  43. mLiczbsOcenET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  44. @Override
  45. public void onFocusChange(View v, boolean hasFocus) {
  46. if (!hasFocus){
  47. String liczbaOcen=mLiczbsOcenET.getText().toString();
  48. if (liczbaOcen==null || liczbaOcen.isEmpty())
  49. mLiczbsOcenET.setError("Pole Liczba ocen nie może być puste");
  50.  
  51. else if (Integer.valueOf(liczbaOcen) < 5 || Integer.valueOf(liczbaOcen) > 15) {
  52. mLiczbsOcenET.setError("Musisz podać liczbę z przedziału 5-15");
  53. }
  54. }
  55. }
  56. });
  57.  
  58. public void buttonVisibility() {
  59. if (imie == null || imie.isEmpty() || nazwisko == null || nazwisko.isEmpty() || liczbaOcen == null || liczbaOcen.isEmpty() || Integer.valueOf(liczbaOcen) < 5 || Integer.valueOf(liczbaOcen) > 15)
  60. mOcenyB.setVisibility(View.INVISIBLE);
  61. else
  62. mOcenyB.setVisibility(View.VISIBLE);
  63. }
  64. }
  65.  
  66. private EditText mImieET;
  67. private EditText mNazwiskoET;
  68. private EditText mLiczbsOcenET;
  69. private Button mOcenyB;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement