Created
January 17, 2018 22:00
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.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(3); | |
EditText txt4 = (EditText) ze.lastRow.getChildAt(4); | |
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(); | |
} | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment