How to add multiple buttons on a single AlertDialog

前端 未结 5 475
暗喜
暗喜 2020-12-14 06:12

I have a butoon, on clicking of this button i want to open multiple buttons on a single AlertDialog like this :\"enter

5条回答
  •  独厮守ぢ
    2020-12-14 06:35

    I would inflate the AlertDialog with my own custom view (my_alert_dialog.xml).

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    LayoutInflater inflater = getLayoutInflater();
    //inflate view for alertdialog since we are using multiple views inside a viewgroup (root = Layout top-level) (linear, relative, framelayout etc..)
    View view = inflater.inflate(R.layout.my_alert_dialog, (ViewGroup) findViewById(R.id.root)); 
    
    Button button1 = (Button) view.findViewById(R.id.button1); // etc.. for button2,3,4.
    alert.setView(view);
    alert.show();
    

提交回复
热议问题