如何使用Multichoice项目和EditText制作Alertdialog?

时间:2018-10-17 13:22:37

标签: android listview alertdialog multichoiceitems

我有一个{strong>多项选择项中的AlertDialog。我想在每个项旁边有一个EditText。我该如何实现?

 third_card.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final AlertDialog.Builder mBuilder = new AlertDialog.Builder(EnterRecordActivity.this);
                mBuilder.setTitle("Select Contributor");
                mBuilder.setMultiChoiceItems(listMembers, checkedMembers, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int position, boolean isChecked) {

                    }
                });
                mDialog = mBuilder.create();
                mDialog.show();
            }
        });

这是我到目前为止使用以下代码实现的

this is what i achieved till now with the following code

this is what i want

这就是我想要的。包含每个选择项的编辑文本

2 个答案:

答案 0 :(得分:1)

创建自定义对话框,如下所示:

     AlertDialog.Builder builder = new AlertDialog.Builder(this);
            LayoutInflater inflater = (this).getLayoutInflater();
            //Your layout file name is custom_check_with_edt
            View dialogView = inflater.inflate(R.layout.custom_check_with_edt, null);
           //get Id from custom view            
            EditText edtNote = dialogView.findViewById(R.id.edt_notes);

            builder.setView(dialogView);
            builder.setPositiveButton("Ok", (dialog, which) -> {
                   //YOUR LOGIC
                }
                dialog.dismiss();
            });
            builder.setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
            builder.setCancelable(true);
            Dialog dialog = builder.create();
            dialog.show();

答案 1 :(得分:0)

您可以通过创建扩展对话框类的类来创建自定义对话框。然后,您需要添加xml文件的布局。跟随此链接How to create a Custom Dialog box in android? 对于多选和editext,请使用listview或recycler视图,并使用复选框和edittext定义项目布局。