É possível manter um Diálogo aberto depois de clicar no Botão Neutro? [duplicado]
Esta questão já tem uma resposta aqui:
Como impedir que um diálogo feche quando um botão é clicado 18 respostasEu tenho um Dialog com 3 EditTexts que eu uso para obter um endereço de FTP, nome de usuário e senha. Eu usei .setNeutralButton para criar um botão para "Testar Conexão". Consegui trabalhar para conectar ao ftp e mostrar um Toast com o resultado, mas não quero que o botão de teste feche o Dialog. Como posso manter a caixa de diálogo aberta durante o teste de conexão?
livePreviewChk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout lila1 = new LinearLayout(NewSite.this);
lila1.setOrientation(1); // 1 is for vertical orientation
final EditText serverName = new EditText(NewSite.this);
serverName.setHint("Server name");
final EditText serverAddress = new EditText(NewSite.this);
serverAddress.setHint("Server Address");
final EditText username = new EditText(NewSite.this);
username.setHint("Username:");
final EditText password = new EditText(NewSite.this);
password.setHint("Password");
AlertDialog.Builder alt_bld = new AlertDialog.Builder(
NewSite.this);
alt_bld.setIcon(R.drawable.ftpicon);
alt_bld.setTitle("Enter the login details for the host FTP")
.setCancelable(true)
.setPositiveButton("Save",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
}
})
.setNeutralButton("Test Connection",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
FTPConnector testConnection = new FTPConnector();
boolean status = testConnection
.ftpConnect(host, user, pass,
port);
if (status == true) {
connectionSuccessfull = true;
} else {
connectionSuccessfull = false;
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
lila1.addView(serverName);
lila1.addView(serverAddress);
lila1.addView(username);
lila1.addView(password);
AlertDialog alert = alt_bld.create();
alert.setView(lila1);
alert.show();
}
});