Die Grundidee ist Folgende:
Ein Arbeiter kriegt ein Tablet mit der App in die Hand gedrückt und soll über den Tag verteilt seine bearbeiteten Aufträge mit Maschinentyp, Start- und Endzeit und Kommentaren angeben.
Am Ende speichert er alles und sendet seine Daten an die Datenbank.
Nun will ich halt, dass er keinen Unsinn in die Zeitspalten eintragen kann
Ich hab gerade mal getestet, es liegt definitiv an
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();
}
Alles anzeigen
ich habe dazu die Einträge, die eine neue Zeile einbringen, mal rausgenommen, sodass in der MainActivity nur noch stand
package com.example.cris.zeiterfassungv2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
public TableRow lastRow;
public newRowTextWatcher tw;{
tw= new newRowTextWatcher(this);}
public Sum sum;{
sum= new Sum(this);}
/* public Time24hFormatValidator time24;{
time24 = new Time24hFormatValidator(this );}*/
public void AddRow()
{
TableRow row = new TableRow(MainActivity.this);
EditText txt1 = new EditText(MainActivity.this);
EditText txt2 = new EditText(MainActivity.this);
EditText txt3 = new EditText(MainActivity.this);
EditText txt4 = new EditText(MainActivity.this);
EditText txt5 = new EditText(MainActivity.this);
EditText txt6 = new EditText(MainActivity.this);
EditText txt7 = new EditText(MainActivity.this);
row.addView(txt1);
row.addView(txt2);
row.addView(txt3);
row.addView(txt4);
row.addView(txt5);
row.addView(txt6);
row.addView(txt7);
txt1.setBackgroundResource(R.drawable.cellshape);
txt2.setBackgroundResource(R.drawable.cellshape);
txt3.setBackgroundResource(R.drawable.cellshape);
txt4.setBackgroundResource(R.drawable.cellshape);
txt5.setBackgroundResource(R.drawable.cellshape);
txt6.setBackgroundResource(R.drawable.cellshape);
txt7.setBackgroundResource(R.drawable.cellshape);
txt1.setInputType(InputType.TYPE_CLASS_TEXT);
txt2.setInputType(InputType.TYPE_CLASS_TEXT);
txt3.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME);
txt4.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME);
txt5.setInputType(InputType.TYPE_CLASS_NUMBER);
txt6.setInputType(InputType.TYPE_CLASS_TEXT);
txt7.setInputType(InputType.TYPE_CLASS_TEXT);
/* txt3.addTextChangedListener(time24);
txt4.addTextChangedListener(time24);*/
TableLayout table = (TableLayout) findViewById(R.id.tabelle);
table.addView(row);
lastRow = row;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tw = new newRowTextWatcher(this);
/* time24 = new Time24hFormatValidator(this);*/
lastRow = (TableRow) findViewById(R.id.firstRow);
EditText txt1 = (EditText) findViewById(R.id.etOrderNo);
EditText txt2 = (EditText) findViewById(R.id.etMachineID);
EditText txt3 = (EditText) findViewById(R.id.etstarttime);
EditText txt4 = (EditText) findViewById(R.id.etendtime);
EditText txt5 = (EditText) findViewById(R.id.etdecimaltime);
EditText txt6 = (EditText) findViewById(R.id.etrework);
EditText txt7 = (EditText) findViewById(R.id.etstatus);
txt3.addTextChangedListener(new Time24hFormatValidator(this));
txt4.addTextChangedListener(new Time24hFormatValidator(this));
Alles anzeigen