Alertdialog not_showing

后端 未结 2 911
忘掉有多难
忘掉有多难 2021-01-27 02:06

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

相关标签:
2条回答
  • 2021-01-27 02:43

    Declare Variable globally

    AlertDialog alertDialog ;
    

    add this after your negative button click

    alertDialog = builder.create();
            alertDialog.show();
    
    0 讨论(0)
  • 2021-01-27 03:03

    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");
            }
        });
    
    0 讨论(0)
提交回复
热议问题