Closing Dialog when button clicked

  • Replies:0
  • Forum posts: 8

Jun 8, 2015, 10:16:20 AM via Website


I am developing my first Android app and I have the first version almost finished, the problem is that I am stucked in a pretty stupid point…

The thing is the following, simplificating I’ve got an activity with a button, when button presed I open an Android dialog wich:

  • Capture a signature as bitmap
  • Present a “Reset” button that cleans the image to write again
  • Also a “Save” button which, onClick, saves the image as bitmap inside application folder

When I click outter the dialog, this is dismissed and in that event I can show the captured image in the main Activity as a little image (to see the signature), but I would like to dismiss the dialog at the same time when I press “Save” button.

The “problem” is that I don’t know where I have to use the event, I am guessing this has to be done in the main activity, but I don’t know how to catch an event of a button located in the Dialog and not the activity itself. And I think you can’t close the dialog itself catching the event inside the Dialog.

I found some code that shows how to access dialog button from main activity by using FindByView( but an additional problem is that this “save” button I create it programatically in the moment of loading the dialog.

I hope you can give me a clue!.

Thanks so much in advance.