我真的非常绝望
我被迫使用Android应用程序,但我的代码不会
有三个文本观察者,一个在第一行插入一个字符后立即向表中添加一行
秒检查时间格式
第三个使用endtime-starttime创建小数时间
第一部作品,第二部作品和第三作品
MainActivity 公共类MainActivity扩展了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 );}
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(time24);
txt4.addTextChangedListener(time24);
txt1.addTextChangedListener(tw);
txt2.addTextChangedListener(tw);
txt3.addTextChangedListener(tw);
txt4.addTextChangedListener(tw);
txt5.addTextChangedListener(tw);
txt6.addTextChangedListener(tw);
txt7.addTextChangedListener(tw);
newrowtextwatcher
public class newRowTextWatcher implements TextWatcher {
MainActivity ze;
public newRowTextWatcher(MainActivity Zeiterfassung) {
ze = Zeiterfassung;
}
public void afterTextChanged(Editable editable) {
EditText txt1 = (EditText) ze.lastRow.getChildAt(0);
EditText txt2 = (EditText) ze.lastRow.getChildAt(1);
EditText txt3 = (EditText) ze.lastRow.getChildAt(2);
EditText txt4 = (EditText) ze.lastRow.getChildAt(3);
EditText txt5 = (EditText) ze.lastRow.getChildAt(4);
EditText txt6 = (EditText) ze.lastRow.getChildAt(5);
EditText txt7 = (EditText) ze.lastRow.getChildAt(6);
if (txt1.getText().toString().equals("") &&
txt2.getText().toString().equals("") &&
txt3.getText().toString().equals("") &&
txt4.getText().toString().equals("") &&
txt5.getText().toString().equals("") &&
txt6.getText().toString().equals("") &&
txt7.getText().toString().equals(""))
{
return;
}
else
ze.AddRow();
验证
public class Time24hFormatValidator implements TextWatcher {
MainActivity ze;
public Time24hFormatValidator(MainActivity Zeiterfassung) {
ze = Zeiterfassung;
}
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();
}
}}
请帮助
答案 0 :(得分:0)
此
public void afterTextChanged(Editable editable)
被定义为常规无效,尝试将@Override置于其上,如下所示,因此它会知道您的意思是您已经实施的课程的空白。
@Override
public void afterTextChanged(Editable s) {
}