1

I am creating a multi-choice list of banks. When user selects multiple banks I want to show the count of selected banks in the top right corner, beside the title of alert dialog.

I also want to customize check box and banks names[list items] Can I do that in alert dialog and how can I achieve this?

Makarand
  • 983
  • 9
  • 27

1 Answers1

2

Yes, you create a custom AlertDialog for it. First make a layout for it. Then use it to customize AlertDialog like this-

LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
                    View view = layoutInflater.inflate(R.layout.popup_layout,null);
                    final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
                    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    alertDialog.setView(view);

                    //You can find your view like this
                    TextView txtMsg = (TextView) view.findViewById(R.id.txtMsg);
                    txtMsg.setText("");

                    //Or if u want to provide any button
                    view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            alertDialog.dismiss();
                            // your function
                        }
                    });
                    alertDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;     //if u want to give any animation
                    alertDialog.show();
Ajay Gohel
  • 243
  • 7
  • 17
  • Thank you. It worked, but now I got performance issue. I created list view showing checkbox and list of banks for multiple selection. I used custom adapter for that, but it lags too much. Is there any solution for this?? – Makarand Dec 14 '18 at 13:28