Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2018 19:52
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/68e0a3adf56214652cd2f0e5ce2d4ba2 to your computer and use it in GitHub Desktop.
Save anonymous/68e0a3adf56214652cd2f0e5ce2d4ba2 to your computer and use it in GitHub Desktop.
package com.example.cris.zeiterfassungv2;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Toast;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
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(0);
EditText txt4 = (EditText) ze.lastRow.getChildAt(1);
String str = txt3.getText().toString();
if(!str.equals(""))
{
String[] parts = str.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(!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