필요한 EditText를 만들려고합니다. 부울로 시도하지만 작동하지 않습니다. 내 EditText에 txtEdat, txtTelefon, txtEmail에만 무언가를 입력해도 setError가 사라지지 않습니다 ... 부울은 txtEmail (마지막 코드)을 인식하기 때문에이 코드에서는 쓸모없는 것처럼 보입니다.필수 EditText Android가 작동하지 않습니다.
boolean contador;
contador = false;
//Creem el intent
Intent iIntent = new Intent(MyActivity.this, FormEnviado.class);
//Creem un bundle que es on anira la informació que es pasarà a la altre activity
Bundle bBundle = new Bundle();
// si isChecked el valor es True
bBundle.putBoolean("cbValidator", cbDades.isChecked());
// En cada if mirem si hi ha algun camp buit
bBundle.putString("cognom", txtCognom.getText().toString());
if(txtCognom.getText().toString().length()==0)
{
contador = false;
txtCognom.setError("Aquet camp no pot estar buit");
}
else
{
contador = true;
}
bBundle.putString("nom", txtNom.getText().toString());
if(txtNom.getText().toString().length()==0)
{
contador = false;
txtNom.setError("Aquet camp no pot estar buit");
}
else
{
contador = true;
}
bBundle.putString("edat", txtEdat.getText().toString());
if(txtEdat.getText().toString().length()==0)
{
contador = false;
txtEdat.setError("Aquet camp no pot estar buit");
}
else
{
contador = true;
}
bBundle.putString("telefon", txtTelefon.getText().toString());
if(txtTelefon.getText().toString().length()==0)
{
contador = false;
txtTelefon.setError("Aquet camp no pot estar buit");
}
else
{
contador = true;
}
bBundle.putString("email", txtEmail.getText().toString());
if(txtEmail.getText().toString().length()==0)
{
contador = false;
txtEmail.setError("Aquet camp no pot estar buit");
}
else
{
contador = true;
}
// Toast i no ens deixarà enviar-lo
if (!contador)
{
Toast.makeText(getApplicationContext(), "Has de omplir el formulair per enviar-lo", Toast.LENGTH_SHORT).show();
}
// Formulario omplert
else
{
//Afegim la informació de bundle al intent
iIntent.putExtras(bBundle);
//Inicialitzem el intent
startActivity(iIntent);
}
그냥 팁 :'iIntent' 대신'intent'를 사용할 수 있습니다. – Simas
나도 잘 압니다 만, 제 생각에는 아무 것도 바뀌지 않는다고 생각합니다 ... –
모든 필드가 필요합니다 (비어 있지 않음)? –