Created
January 17, 2018 18:46
-
-
Save anonymous/d6e69a601c6e05ef439e1d0a816ee989 to your computer and use it in GitHub Desktop.
This file contains 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 com.example.MrX.zeiterfassungv2; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class Time24hFormatValidator implements TextWatcher { | |
MainActivity ze; | |
public Time24hFormatValidator(MainActivity Zeiterfassung) { | |
ze = Zeiterfassung; | |
} | |
@Override | |
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |
} | |
@Override | |
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) | |
{ | |
} | |
@Override | |
public void afterTextChanged(Editable editable) { | |
EditText txt3 = (EditText) ze.lastRow.getChildAt(2); | |
EditText txt4 = (EditText) ze.lastRow.getChildAt(3); | |
if(!txt3.getText().toString().equals("")) | |
{ | |
String[] parts = txt3.getText().toString().split("."); | |
String part1 = parts[0]; | |
String part2 = parts[1]; | |
int hours = Integer.parseInt(part1); | |
int minutes= Integer.parseInt(part2); | |
if (hours>=0 && hours<24) | |
{ | |
return; | |
} else | |
txt3.setText(""); | |
Toast.makeText(ze.getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show(); | |
if (minutes>=0 && minutes<60) | |
{ | |
return; | |
} else | |
txt3.setText(""); | |
Toast.makeText(ze.getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show(); | |
} | |
if(!txt4.getText().toString().equals("")) | |
{ | |
String[] parts = txt4.getText().toString().split("."); | |
String part1 = parts[0]; | |
String part2 = parts[1]; | |
int hours = Integer.parseInt(part1); | |
int minutes= Integer.parseInt(part2); | |
if (hours>=0 || hours<24) | |
{ | |
return; | |
} else | |
txt4.setText(""); | |
Toast.makeText(ze.getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show(); | |
if (minutes>=0 || minutes<60) | |
{ | |
return; | |
} else | |
txt4.setText(""); | |
Toast.makeText(ze.getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment