1
I have a AlertDialog
and inside of it I have a EditText
and need to validate and after validate run the method enviarEmail()
, how do I do?
Man AlertDialog
:
AlertDialog.Builder caixaDialog = new AlertDialog.Builder(getContext());
caixaDialog.setView(vView)
.setCancelable(false)
.setPositiveButton("Enviar", null)
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
// Habilitar todos os botões
btnSatisfacaoRuim.setBackgroundResource(R.drawable.img_satisfacao_ruim);
btnSatisfacaoBom.setBackgroundResource(R.drawable.img_satisfacao_bom);
btnSatisfacaoNormal.setBackgroundResource(R.drawable.img_satisfacao_normal);
llSatisfacao.setVisibility(View.INVISIBLE);
}
});
final AlertDialog mDialog = caixaDialog.create();
mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button positive = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
positive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (edtMensagemSatEmail.getText().length() == 0) {
edtMensagemSatEmail.setError("Campo obrigatório");
edtMensagemSatEmail.setFocusable(true);
edtMensagemSatEmail.requestFocus();
} else {
// Barra de progresso
progresso = new ProgressDialog(getContext());
progresso.setCancelable(false);
progresso.setMessage("Processando...");
progresso.show();
// Metodo de envio
inserirWEBService();
enviarEmail();
mDialog.dismiss();
}
getFragmentManager().beginTransaction().replace(R.id.content_principal, new avalieViagem()).addToBackStack(null).commit();
}
});
}
});
mDialog.show();
My XML from Dialog
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Linha: "
android:textColor="#548ddf"
android:textSize="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_linha_sat_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="linha"
android:textColor="#548ddf"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Horário: "
android:textColor="#548ddf"
android:textSize="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/txt_horario_sat_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="horario"
android:textColor="#548ddf"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/textView1"
app:layout_constraintTop_toBottomOf="@+id/txt_linha_sat_email" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/img_sat_email"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="5dp"
app:srcCompat="@drawable/img_satisfacao_bom_off"
tools:layout_editor_absoluteX="10dp"
tools:layout_editor_absoluteY="69dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/txt_satisfacao_sat_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="satisfacao"
android:textColor="#548ddf"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_sat_email" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Deixe seu Comentário:"
android:textColor="#548ddf"
android:textSize="18dp" />
<EditText
android:id="@+id/txt_Mensagem_sat_email"
android:layout_width="250dp"
android:layout_height="100dp"
android:layout_marginTop="0dp"
android:background="#d8d6d3"
android:gravity="top|left"
android:hint="Comente aqui"
android:inputType="textMultiLine"
android:lines="6"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:scrollHorizontally="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
What’s wrong with your code?
– ramaral
He’s not validating the
EditText
when I click SendAlertDialog
.– Ari Melo
txtMensagemSatEmail is a Textview ta wanting to validate a Textview? Ta validating something based on a Textview ?
– Ricardo Lucas
He is a
EditText
, was only the variable name.– Ari Melo
It wouldn’t be enough for one
return
at the end of the code within theif
?– ramaral
Put, just closed the
AlertDialog
.– Ari Melo
If you want to keep the dialog open in case the entered data is not valid see this reply.
– ramaral
I couldn’t, in the second step, I freeze, in the part of declaring the
button
, there is nosetButton
.– Ari Melo