I have an Alert Dialog which has a list on it, and i want to close onlistclick is it possible?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final String[] Categories = SQLiteHelper.getAllCategories();//this is where i get the array for my list
ListView myList = new ListView(this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.alert_dialog_list_view, Categories);
myList.setAdapter(adapter);
myList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
//doing something in here and then close
}
});
builder.setTitle("Please Choose");
builder.setInverseBackgroundForced(true);
builder.setView(myList);
final Dialog dialog = builder.create();
dialog.show();
}
The alert dialog is running perfect i just dont want to put any buttons in it.
AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.
then((exit) { if (exit == null) return; if (exit) { // user pressed Yes button } else { // user pressed No button } }); The below code will close AlertBox/DialogBox in Flutter. Navigator. of(context).
AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .
By default, dialog can be closed by pressing Esc key and clicking the close icon on the right of dialog header. It can also be closed by clicking outside of the dialog using hide method. Set the CloseOnEscape property value to false to prevent closing of the dialog when pressing Esc key.
If you define the onItemClickListener
after the Dialog
you can just call dialog.dismiss();
in the onItemClick()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With