How to set button click listener for Custom Dialog?

 dialog_bring_button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

              final Dialog dialog = new Dialog(MyActivity.this);
              dialog.setContentView(R.layout.MyCustomDialogxmlfile);

              dialog.show(); 

            /* My Cancel Button , and its listener */

              my_cancel_btn=(Button)dialog.findViewById(R.id.datesetbtn);
              my_cancel_btn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                     dialog.dismiss();
                }
            });

        }
    });

There you go:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(id);

    Button signInbutton=(Button)findViewById(R.id.signInButton);
    signInButton.setOnClickListener(this);
    Button closebutton=(Button)findViewById(R.id.closeButton);
    closeButton.setOnClickListener(this);
    }

@Override
public void onClick(View v) {
    if(R.id.closeButton == v.getId()) { 
        closeButton(v);
    } else {

    // do the same for signInButton
    }

}

Suggest you learn the basic beforehand.

Tags:

Android