How to set Single Choice Items inside AlertDialog?

前端 未结 2 517
故里飘歌
故里飘歌 2021-02-11 14:42

I haven\'t been able to set a Single Choice list, or a Multiple Choice List inside an AlertDialog.

I tried following the examples but I only get a Dialog with a Title, t

2条回答
  •  再見小時候
    2021-02-11 15:02

    this code works for me

     final CharSequence[] charSequence = new CharSequence[] {"As Guest","I have account here"};
    
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Buy Now")
                    //.setMessage("You can buy our products without registration too. Enjoy the shopping")
                    .setSingleChoiceItems(charSequence, 0, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            utility.toast(" "+charSequence);
                        }
                    })
            .setPositiveButton("Go", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show()
    

提交回复
热议问题