0
,當我點擊提交按鈕,確認沒有被處理是有沒有搞錯?如果編輯文本爲空,它會進入到下一個活動驗證不被處理?任何一個可以解決這個問題在驗證
public void submitDetails(View v)
{
et = (EditText)findViewById(R.id.first);
et1 = (EditText)findViewById(R.id.last);
et2 = (EditText)findViewById(R.id.email);
et3 = (EditText)findViewById(R.id.phone);
et4 = (EditText)findViewById(R.id.dateofbirth);
et5 = (EditText)findViewById(R.id.Address);
btn = (Button)findViewById(R.id.submit);
String first = et.getText().toString();
String last = et1.getText().toString();
String email = et2.getText().toString();
String mobile = et3.getText().toString();
String birth = et4.getText().toString();
String address = et5.getText().toString();
String emailpatern = "[a-zA-Z0-9._-][email protected][a-z]+\\.+[a-z]+";
if (et.equals(""))
et.setError("pls enter name");
else if (et2.equals("")&&!et2.equals(emailpatern))
et2.setError("Pls Enter Valid Email");
else if(et3.equals(""))
et3.setError("Enter Mobile Number");
else if (et4.equals(""))
et4.setError("Enter Date of Birth");
else if (et5.equals(""))
et5.setError("fil the fileds");
else
{
Intent i = new Intent(MainActivity.this,Result.class);
i.putExtra("k1",first);
i.putExtra("k2",last);
i.putExtra("k3",email);
i.putExtra("k4",mobile);
i.putExtra("k5",birth);
i.putExtra("k6",address);
startActivity(i);
}
}
它看起來像你比較EditText對象本身而不是文本。你有很多變量獲取文本,爲什麼不使用它們?例如,而不是'if(et.equals',使用'if(first.equals'? – Austin