{"id":914,"date":"2015-09-11T16:47:07","date_gmt":"2015-09-11T23:47:07","guid":{"rendered":"http:\/\/appinventor.pevest.com\/?p=914"},"modified":"2015-09-11T16:47:07","modified_gmt":"2015-09-11T23:47:07","slug":"how-to-use-the-2-button-notifier-dialog-box","status":"publish","type":"post","link":"https:\/\/coldstreams.com\/appinventor\/2015\/09\/11\/how-to-use-the-2-button-notifier-dialog-box\/","title":{"rendered":"How to use the &#8220;2 Button&#8221; Notifier dialog box"},"content":{"rendered":"<p>A reader asked, &#8220;<em>When using the 2 button Notifier dialog, how do we know which button was pressed?<\/em>&#8221;<\/p>\n<p>The 2 button Notifier dialog alert box displays 3 buttons(!) &#8211; the first two have values you specify, such as &#8220;Ok&#8221; and &#8220;Done&#8221;, as shown here, and the third is an optional generic &#8220;Cancel&#8221; button:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Screenshot_2015-09-11-15-07-15.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-915\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Screenshot_2015-09-11-15-07-15-576x1024.gif\" alt=\"Screenshot_2015-09-11-15-07-15\" width=\"304\" height=\"540\" \/><\/a><\/p>\n<p><em>The\u00a0Notifier<\/em> component block is a procedure call that has no return value &#8211; s<em>o how can you determine which button was selected?<\/em><\/p>\n<p>The answer is that the selected button is returned to\u00a0a separate event handler.<\/p>\n<p><!--more--><\/p>\n<h2>Designer View<\/h2>\n<p>First, let us set up an example program to demonstrate. Here is a Designer view with a button &#8220;Demo the 2 button Notifier&#8221;, and two text labels, the last of which \u00a0displays the content of the selected button from the <em>Notifier<\/em>:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Notifier2Buttons_Designer.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-916\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Notifier2Buttons_Designer-601x1024.gif\" alt=\"Notifier2Buttons_Designer\" width=\"302\" height=\"514\" \/><\/a><\/p>\n<p>Drag the <em>Notifier1<\/em>\u00a0component Palette to the work area; it appears beneath the work area as a &#8220;non-visible&#8221; component.<\/p>\n<h2>Blocks Code<\/h2>\n<p>The <em>Click<\/em> event handler for the\u00a0<em>btnStartDemo<\/em> button calls the <em>Notifier&#8217;s<\/em> <em>ShowChooseDialog<\/em> procedure, where we specify the text for Button 1 and for Button 2.\u00a0That call displays the dialog box on screen.<\/p>\n<p>After the user pressed a button, the <em>Notifier<\/em> generates an\u00a0<em>AfterChoosing<\/em> event. The parameter <em>choice<\/em> contains the text of the button that was pressed.<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Notifier2Buttons_Blocks2.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-917\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Notifier2Buttons_Blocks2-1024x931.gif\" alt=\"Notifier2Buttons_Blocks2\" width=\"468\" height=\"425\" \/><\/a><\/p>\n<p>The <em>AfterChoosing<\/em> event handler copies\u00a0<em>choice<\/em> to the text label\u00a0to show\u00a0which button was selected. The value of <em>choice<\/em> can be compared in an <em>if-then<\/em>\u00a0block to determine how the app should proceed. If\u00a0the &#8220;Ok&#8221;\u00a0button was pressed, then the status message is set to the color green, otherwise the text\u00a0is set to blue.<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Untitled.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-930\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2015\/09\/Untitled-576x1024.gif\" alt=\"Untitled\" width=\"295\" height=\"525\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A reader asked, &#8220;When using the 2 button Notifier dialog, how do we know which button was pressed?&#8221; The 2 button Notifier dialog alert box displays 3 buttons(!) &#8211; the first two have values you specify, such as &#8220;Ok&#8221; and &#8220;Done&#8221;, as shown here, and the third is an optional generic &#8220;Cancel&#8221; button: The\u00a0Notifier component &hellip; <a href=\"https:\/\/coldstreams.com\/appinventor\/2015\/09\/11\/how-to-use-the-2-button-notifier-dialog-box\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to use the &#8220;2 Button&#8221; Notifier dialog box<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,10],"tags":[19,22,28,82,126,129,136,151,176,181,192],"class_list":["post-914","post","type-post","status-publish","format-standard","hentry","category-android-development","category-components","category-programming-method","tag-android","tag-app-inventor","tag-appinventor","tag-education","tag-method","tag-mit","tag-notifier","tag-programming","tag-software","tag-stem","tag-technique"],"_links":{"self":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/comments?post=914"}],"version-history":[{"count":0,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/914\/revisions"}],"wp:attachment":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/media?parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/categories?post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/tags?post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}