0
I have an android app with a home screen, where there is a listview, and when I click on the listview she opens a alertdialog, that displayed the following message "Want to Start Maintenance ?", and has two buttons "YES" and "NO", if the user cleaves into "YES", then he should open another screen and pass the parameters of "position" who are in the onItemClick, if the user clicks NO stay on the same screen, how can I do ?
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
AlertDialog.Builder msgBox = new AlertDialog.Builder(this);
msgBox.setTitle("Atenção!");
msgBox.setIcon(android.R.drawable.alert_dark_frame);
msgBox.setMessage("Deseja iniciar Manutenção na ETE?");
msgBox.setPositiveButton("SIM", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Cliente cliente = adpClientes.getItem(position);
Intent intent = new Intent(MainActivity.this, init_manutencao.class);
intent.putExtra("CLIENTE", cliente);
startActivity(intent);
}
});
msgBox.setNegativeButton("NÂO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "Saindo", Toast.LENGTH_SHORT).show();
}
});
msgBox.create();
msgBox.show();
}
When you speak "await the reply of Alertdialog" you refer to the click event of
AlertDialog
?– Ivan Silva
yes, it should wait for the user to click yes, if he clicks yes he passes to the next screen, if he clicks does not continue on the same screen.
– Leonardo Silva
but I also have some position parameters in my onItemClick, which should only be passed if the user click yes
– Leonardo Silva
The
AlertDialog
opens or just does nothing at the click of the button?– Ivan Silva
a Alertdialog opens, and asks if the user wants to proceed to next phase.
– Leonardo Silva
To avoid extensive discussion of the problem, edit your question and make it more specific by indicating possible error messages or unexpected code behavior
– Ivan Silva
I changed the question according to your recommendation Ivan, please if you can help, I will be grateful.
– Leonardo Silva
I don’t understand your doubt. If you want something to be done when the "YES" button is clicked, the code that does that "something" should be placed where it is
Toast.makeText(MainActivity.this, "Iniciando Manutenção", Toast.LENGTH_SHORT).show();
– ramaral
note that I am calling the alertDialog in my public void onItemClick just below I have the screen call, however I need to wait for the user to click YES
– Leonardo Silva