Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d6e69a601c6e05ef439e1d0a816ee989 to your computer and use it in GitHub Desktop.
Save anonymous/d6e69a601c6e05ef439e1d0a816ee989 to your computer and use it in GitHub Desktop.
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