{"id":3446,"date":"2016-06-20T00:00:27","date_gmt":"2016-06-20T00:00:27","guid":{"rendered":"https:\/\/assignment.essayshark.com\/blog\/?p=3446"},"modified":"2023-01-09T13:34:37","modified_gmt":"2023-01-09T13:34:37","slug":"sample-android-application-code","status":"publish","type":"post","link":"https:\/\/assignmentshark.com\/blog\/sample-android-application-code\/","title":{"rendered":"Sample Android Application Code"},"content":{"rendered":"<h2>ANDROID TASK:<\/h2>\n<p>Create new Android application which shows a Happy New Year congratulation message and appropriate background picture. When the text corresponding to a family member getting congratulated is being clicked on by the user, it should respond with switching to a different family member (i.e. father, mother, brother, grandfather).<!--more--><\/p>\n<h2>SOLUTION:<\/h2>\n<p>In this sample we will show such features as the import and use of images, as well as switching between several string type elements (using if&#8230;else). For now let&#8217;s create a new Android application and remove \u201cHello world!\u201d message as well as everything else, instead setting up an empty Relative Layout. It will look like this at the beginning:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image001-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3450\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image001-2.jpg\" alt=\"image001\" width=\"405\" height=\"531\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image001-2.jpg 405w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image001-2-229x300.jpg 229w\" sizes=\"auto, (max-width: 405px) 100vw, 405px\" \/><\/a><\/p>\n<p>Let&#8217;s add TextView with a message &#8220;Happy New Year!&#8221;, also specifying a large enough font size:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image002-4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3454\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image002-4.jpg\" alt=\"image002\" width=\"563\" height=\"314\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image002-4.jpg 563w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image002-4-300x167.jpg 300w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image003-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3456\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image003-1.jpg\" alt=\"image003\" width=\"396\" height=\"528\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image003-1.jpg 396w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image003-1-225x300.jpg 225w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><\/p>\n<p>Let&#8217;s add background picture. For this you should go to Project viewer on the left side of Android Studio window and navigate to app&gt;res&gt;drawable folder, and then just copy an existing image file to there with \u201cCtrl+C \u2013 Ctrl+V\u201d. You will get promted for entering new filename, in our case we will leave it as newyear.png<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image004.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3458\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image004.jpg\" alt=\"image004\" width=\"273\" height=\"226\" \/><\/a><\/p>\n<p>Let&#8217;s try implementing background image (ImageView element) and see how it will look:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image005.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3460\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image005.jpg\" alt=\"image005\" width=\"567\" height=\"420\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image005.jpg 567w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image005-300x222.jpg 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p>We can see that the image isn&#8217;t covering the screen fully, and its edges are somewhat visible, which is undesirable. We will fix this with using scaleType = centerCrop. Additionally, we will add padding and color to the text. Finally, we will add the extra TextView section mentioning a family member (the section that will become interactive later).<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image006.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3462\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image006.jpg\" alt=\"image006\" width=\"393\" height=\"536\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image006.jpg 393w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image006-220x300.jpg 220w\" sizes=\"auto, (max-width: 393px) 100vw, 393px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image007.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3464\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image007.jpg\" alt=\"image007\" width=\"356\" height=\"495\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image007.jpg 356w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image007-216x300.jpg 216w\" sizes=\"auto, (max-width: 356px) 100vw, 356px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image008.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3466\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image008.jpg\" alt=\"image008\" width=\"452\" height=\"464\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image008.jpg 452w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image008-292x300.jpg 292w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/a><\/p>\n<p>Now let&#8217;s add an onClick method called clickSwitcher to this TextView.<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image009.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3468\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image009.jpg\" alt=\"image009\" width=\"358\" height=\"228\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image009.jpg 358w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image009-300x191.jpg 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/a><\/p>\n<p>An implementation of this method in MainActivity.java will look as following:<\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image010.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3470\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image010.jpg\" alt=\"image010\" width=\"564\" height=\"541\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image010.jpg 564w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image010-300x288.jpg 300w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><\/p>\n<p>The code is pretty much self-explanatory, we created four string variables corresponding to the family members, then our method detects a View it was summoned by (in this case a clickable TextView) using findViewById method. We can then attribute pretty much any random name to \u201crecognize\u201d it within the method (in our case it&#8217;s \u201cscoreView\u201d). Afterwards we have used an if..else sequence to set the order of switching between family members (with the current one being stored in an initially \u201cneutral\u201d string variable called \u201cmember\u201d. Finally we apply whatever value was currently stored in \u201cmember\u201d to the TextView itself, essentially causing it to change on the screen each time user clicks on it.<\/p>\n<p>Result of running the application and clicking on the appropriate TextView:<br \/>\n<a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image011.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3472\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image011.jpg\" alt=\"image011\" width=\"240\" height=\"410\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image011.jpg 240w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image011-176x300.jpg 176w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image012.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3474\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image012.jpg\" alt=\"image012\" width=\"240\" height=\"410\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image012.jpg 240w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image012-176x300.jpg 176w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image013.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3476\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image013.jpg\" alt=\"image013\" width=\"240\" height=\"410\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image013.jpg 240w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image013-176x300.jpg 176w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image014.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3478\" style=\"max-width: 100%; height: auto;\" src=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image014.jpg\" alt=\"image014\" width=\"240\" height=\"410\" srcset=\"https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image014.jpg 240w, https:\/\/assignmentshark.com\/blog\/wp-content\/uploads\/2016\/06\/image014-176x300.jpg 176w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/a><\/p>\n<h2>Homework Assignments Assistance from the Experts<\/h2>\n<blockquote><p><em>The sample Android application code you&#8217;ve read was completed by one of AssignmentShark experts to demonstrate how similar projects should be completed. If you need <a href=\"https:\/\/assignmentshark.com\/\" target=\"_blank\" rel=\"noopener\">assignment help<\/a> with any of your technical tasks, feel free to contact us any time of the day and night.<\/em><\/p>\n<p>You can also look through another post within this category &#8211; <a href=\"https:\/\/assignmentshark.com\/blog\/android-development-examples-application-development\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/assignmentshark.com\/blog\/android-development-examples-application-development\/<\/a>. Or ask for assistance with any other discipline and assignment type. For example, an <a href=\"https:\/\/assignmentshark.com\/accounting-homework-help.html\" target=\"_blank\" rel=\"noopener\">accounting homework help<\/a> is available 24\/7 whenever you need it.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>ANDROID TASK: Create new Android application which shows a Happy New Year congratulation message and appropriate background picture. When the text corresponding to a family member getting congratulated is being clicked on by the user, it should respond with switching to a different family member (i.e. father, mother, brother, grandfather).<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53,35],"tags":[],"class_list":["post-3446","post","type-post","status-publish","format-standard","hentry","category-it","category-samples"],"_links":{"self":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/comments?post=3446"}],"version-history":[{"count":14,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3446\/revisions"}],"predecessor-version":[{"id":13499,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/posts\/3446\/revisions\/13499"}],"wp:attachment":[{"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/media?parent=3446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/categories?post=3446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/assignmentshark.com\/blog\/wp-json\/wp\/v2\/tags?post=3446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}