alertDialog with PositiveButton and NegativeButton from xml

后端 未结 2 992
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 07:01

I have alert dialog and both PositiveButton and NegativeButton sited programmatically , i want to retrieve them from xml layout ,i try to do it but im new to android develop

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-22 07:48

    XML Code:

    
    
    
          

    Java Code:

    // custom dialog
    final Dialog dialog = new Dialog(context);
    //name of xml - custom
    dialog.setContentView(R.layout.custom);
    
    // set the custom dialog components - text, image and button
    Button dialogButtonOK = (Button) dialog.findViewById(R.id.dialogButtonOK);
    Button dialogButtonCancell = (Button) dialog.findViewById(R.id.dialogButtonCancell);
    
      dialog.setTitle("Warning!!!!!");
    
    // if button is clicked, call some method..
    dialogButtonOk.setOnClickListener(new OnClickListener() {
    
        public void onClick(View v) {
        someMethod();
        }
    });
    
    dialogButtonCancell.setOnClickListener(new OnClickListener() {
       public void onClick(View v) {                            
       dialog.dismiss();                        
       }
    });
    dialog.show();
    

提交回复
热议问题