I am new to android development. tried to implement android dialog in my project but the it\'s not showing .There are no errors in the logcat.
This is the XML co
Declare Variable globally
AlertDialog alertDialog ;
add this after your negative button click
alertDialog = builder.create();
alertDialog.show();
You forgot to use alertDialog.show(); to display your AlertDialog
Check your code you have put alertDialog.show();
inside builder.setNegativeButton
that's why your alertDialog
is not displaying
Change your code like below code
add_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Create item list");
final EditText enter_item_list=new EditText(MainActivity.this);
enter_item_list.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
enter_item_list.setHint("Type a name");
enter_item_list.setHintTextColor(Color.RED);
builder.setView(enter_item_list);
builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String item_name = enter_item_list.getText().toString().trim();
add_item_to_list(item_name);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which) {
dialogInterface.dismiss();
}
});
AlertDialog alertDialog=builder.create();
alertDialog.show();
itemList_ref = Firestore_ref.collection("itemList").document(UserEmail).collection("user_item_list");
}
});