{"id":1545,"date":"2012-12-01T21:50:07","date_gmt":"2012-12-01T17:50:07","guid":{"rendered":"http:\/\/nayarweb.com\/blog\/?p=1545"},"modified":"2013-04-15T23:54:03","modified_gmt":"2013-04-15T19:54:03","slug":"making-my-first-android-app-mera-calculator","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2012\/making-my-first-android-app-mera-calculator\/","title":{"rendered":"Making My First Android App: Mera Calculator"},"content":{"rendered":"<p>Made a tiny calculator in a jiffy. Nothing fancy in here to see. Just seeing how the platform works \ud83d\ude09<\/p>\n<h2><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/11\/SC20121130-190216.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1546\" title=\"SC20121130-190216\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/11\/SC20121130-190216-225x300.png\" alt=\"Mera Android Calculator\" width=\"225\" height=\"300\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/11\/SC20121130-190216-225x300.png 225w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/11\/SC20121130-190216.png 240w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><strong>Making the interface:-<\/strong><\/h2>\n<h3>Adding Buttons:-<\/h3>\n<p>All you have to do is drag the item you want to the specific place you want them to be like in VB.NET<\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot336.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1548\" title=\"snapshot336\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot336-300x249.png\" alt=\"Android SDK on Eclipse User Interface\" width=\"300\" height=\"249\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot336-300x249.png 300w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot336.png 801w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h3>Adding function call to the buttons:-<\/h3>\n<p>Switch from the graphical view to xml view. Add this attribute in the buttons inserting the name of the function to be called.<\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot337.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1549\" title=\"snapshot337\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot337-300x180.png\" alt=\"XML view of Android button\" width=\"300\" height=\"180\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot337-300x180.png 300w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot337.png 440w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>I added this attribute in all buttons.<\/p>\n<h2>Writing the Back-End:-<\/h2>\n<h3>The number button handlers:-<\/h3>\n<p>Now we create methods in java file found in \/src folder. Each button when pressed will concatenate the number or arithmetic operation they do and display it in a TextView named &#8220;textView1&#8221;.<a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot338.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1550\" title=\"snapshot338\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot338-300x108.png\" alt=\"\" width=\"300\" height=\"108\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot338-300x108.png 300w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot338.png 861w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h3>The calculate function:-<\/h3>\n<p>We get the string in &#8220;textView1&#8221; and try to parse it in a function to get a result. The result is then casted as string then the TextView which will display the answer finally displays it \ud83d\ude42<\/p>\n<blockquote><p><a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot339.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1551\" title=\"snapshot339\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot339-300x91.png\" alt=\"\" width=\"300\" height=\"91\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot339-300x91.png 300w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/snapshot339.png 988w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>The program is very buggy and cannot calculate e.g. + and &#8211; at the same time. But at least i got a program running in Android \ud83d\ude1b<\/p><\/blockquote>\n<p>Here are the source codes. The .apk file is found in bin folder: <a href=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2012\/12\/MeraCalculator.zip\">MeraCalculator<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Made a tiny calculator in a jiffy. Nothing fancy in here to see. Just seeing how the platform works \ud83d\ude09 Making the interface:- Adding Buttons:- All you have to do is drag the item you want to the specific place you want them to be like in VB.NET Adding function call to the buttons:- Switch &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2012\/making-my-first-android-app-mera-calculator\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Making My First Android App: Mera Calculator<\/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":[1],"tags":[132,152,139,135],"class_list":["post-1545","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-android","tag-coding","tag-gingerbread","tag-samsung-galaxy-pocket-gt-s5300"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/1545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=1545"}],"version-history":[{"count":6,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/1545\/revisions"}],"predecessor-version":[{"id":1651,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/1545\/revisions\/1651"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=1545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=1545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=1545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}