My DialogButton is not dismissing even though I have .dismiss() in it. My code:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.iabout);
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.iabout);
dialogButton = (Button) dialog.findViewById(R.id.btAboutOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
}
appreciate any help.
Please dont use dialog’s, please use DialogFragments. The are much easier to maintain.
(For pre honeycomb add the support library to your project)
Then in your
DialogFragmentclass use theAlertDialog.Builderin theonCreateDialog(Bdl bundle)like so:These examples can be found here.
At the very lease if you are going to use the old way of using dialogs please at least use the dialog builder.
Then as per the example above you can set the callback methods.
If you you want to do custom dialogs with custom layouts, the use
DialogFragments, then you can control the dialogs lifecycle correctly and then your custom button can just calldismiss()in theDialogFragment.Read the examples as mentioned here.
Cheers,
Chris