{"id":42,"date":"2018-02-07T11:53:15","date_gmt":"2018-02-07T11:53:15","guid":{"rendered":"https:\/\/nezis.gr\/?p=42"},"modified":"2021-12-09T07:44:52","modified_gmt":"2021-12-09T07:44:52","slug":"second-simple-android-program","status":"publish","type":"post","link":"https:\/\/nezis.gr\/?p=42","title":{"rendered":"Second simple Android program"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/developer.android.com\/training\/basics\/firstapp\/images\/screenshot-activity2.png\" alt=\"https:\/\/developer.android.com\/training\/basics\/firstapp\/images\/screenshot-activity2.png\"><\/p>\n<blockquote><p>The user interface for an Android app is built using a hierarchy of:<\/p><\/blockquote>\n<p><strong> Layouts<\/strong> (<a href=\"https:\/\/developer.android.com\/reference\/android\/view\/ViewGroup.html\"><code>ViewGroup<\/code><\/a> objects) are invisible containers that control how its child views are positioned on the screen.<\/p>\n<p><strong>Widgets<\/strong> (<a href=\"https:\/\/developer.android.com\/reference\/android\/view\/View.html\"><code>View<\/code><\/a> objects) are UI components such as buttons and text boxes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/developer.android.com\/images\/viewgroup_2x.png\" alt=\"\" width=\"548\" height=\"240\"><\/p>\n<p><!--more--><\/p>\n<blockquote><p>MainActivity<\/p><\/blockquote>\n<pre>gr.nezis.myfirstapp;\n\nimport android.content.Intent;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.view.View;\nimport android.widget.EditText;\n\n\npublic class MainActivity extends AppCompatActivity {\n\n\n    public static final String EXTRA_MESSAGE = \"com.example.myfirstapp.MESSAGE\";\n\n\n   \/* \u03a5\u03a0\u0395\u03a1\u03a6\u039f\u03a1\u03a4\u03a9\u03a3\u0397\n    \u039c\u03b9\u03b1 \u03ba\u03bb\u03ac\u03c3\u03b7 \u03bc\u03c0\u03bf\u03c1\u03b5\u03af \u03bd\u03b1 \u03b1\u03bb\u03bb\u03ac\u03be\u03b5\u03b9 \u03c4\u03b7 \u03c3\u03c5\u03bc\u03c0\u03b5\u03c1\u03b9\u03c6\u03bf\u03c1\u03ac \u03bc\u03b9\u03b1\u03c2 \u03bc\u03b5\u03b8\u03cc\u03b4\u03bf\u03c5 \u03c0\u03bf\u03c5 \u03b1\u03bb\u03bb\u03b9\u03ce\u03c2 \u03b8\u03b1\n    \u03ba\u03bb\u03b7\u03c1\u03bf\u03bd\u03bf\u03bc\u03bf\u03cd\u03c3\u03b5 \u03b1\u03c0\u03bf \u03c5\u03c0\u03b5\u03c1\u03ba\u03bb\u03ac\u03c3\u03b7 \u03c4\u03b7\u03c2, \u03bf\u03c1\u03af\u03b6\u03bf\u03bd\u03c4\u03ac\u03c2 \u03c4\u03b7\u03bd \u03bc\u03b5 \u03c4\u03bf \u03af\u03b4\u03b9\u03bf \u03cc\u03bd\u03bf\u03bc\u03b1, \u03c4\u03b1 \u03af\u03b4\u03b9\u03b1 \u03bf\u03c1\u03af\u03c3\u03bc\u03b1\u03c4\u03b1,\n    \u03c4\u03bf\u03bd \u03af\u03b4\u03b9\u03bf \u03c4\u03cd\u03c0\u03bf \u03ba\u03b1\u03b9 \u03c4\u03bf \u03c3\u03ce\u03bc\u03b1 \u03c0\u03bf\u03c5 \u03b5\u03c0\u03b9\u03b8\u03c5\u03bc\u03b5\u03af \u03bf \u03c7\u03c1\u03ae\u03c3\u03c4\u03b7\u03c2. (\u0391\u03c1\u03ba\u03b5\u03af \u03bd\u03b1 \u03bc\u03b7\u03bd \u03ad\u03c7\u03b5\u03b9 \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03b7\u03c1\u03b9\u03c3\u03c4\u03b5\u03af \u03c9\u03c2 final).\n    \u03a0\u03b1\u03c1\u03ac\u03b4\u03b5\u03b9\u03b3\u03bc\u03b1\n        class Triangle {\n            public String whoIAm() { return \"I am a triangle\"; }\n            }\n        class EquilateralTriangle extends Triangle {\n        @Overrride\n        public String wh\u03bf\u0399Am() { return \"I am an equilateral triangle\"; }\n    *\/\n\n    @Override \/\/ \u03c5\u03c0\u03b5\u03c1\u03c6\u03cc\u03c1\u03c4\u03c9\u03c3\u03b7 \u03b9\u03b4\u03b9\u03cc\u03c4\u03b7\u03c4\u03c9\u03bd \u03ba\u03b1\u03b9 \u03bc\u03b5\u03b8\u03cc\u03b4\u03c9\u03bd \u03c4\u03b7\u03c2 \u03b2\u03b1\u03c3\u03b9\u03ba\u03ae\u03c2 \u03ba\u03bb\u03ac\u03c3\u03b7\u03c2\n    protected void onCreate(Bundle savedInstanceState) {\n\n        \/\/ call the super class onCreate to complete the creation of activity like the view hierarchy\n        super.onCreate(savedInstanceState);\n\n        \/\/ set the user interface layout for this Activity\n        \/\/ the layout file is defined in the project res\/layout\/main_activity.xml file\n        setContentView(R.layout.activity_main);\n    }\n\n\n\n    public void sendMessage(View view) {\n        \/\/ Do something in response to button\n\n        \/*The Intent constructor takes two parameters:\n        A Context as its first parameter (this is used because the Activity class is a subclass of Context)\n        The Class of the app component to which the system should deliver the Intent (in this case, the activity that should be started).*\/\n\n        Intent intent1 = new Intent(this, DisplayMessageActivity.class);\n\n\n        \/*\n        The putExtra() method adds the EditText's value to the intent. An Intent can carry data types as key-value pairs called extras\n        Your key is a public constant EXTRA_MESSAGE because the next activity uses the key to retrieve the text value.\n        It's a good practice to define keys for intent extras using your app's package name as a prefix. This ensures the keys are unique, in case your app interacts with other apps.\n         *\/\n        EditText editText = (EditText) findViewById(R.id.editText2);\n        String message = editText.getText().toString();\n        intent1.putExtra(EXTRA_MESSAGE, message);\n\n        \/\/The startActivity() method starts an instance of the DisplayMessageActivity specified by the Intent\n        startActivity(intent1);\n\n    }\n\n\n\n}<\/pre>\n<pre>package gr.nezis.myfirstapp;\n\nimport android.content.Intent;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.widget.TextView;\n\npublic class DisplayMessageActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_display_message);\n\n        \/\/ Get the Intent that started this activity and extract the string\n        Intent intent = getIntent();\n        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);\n\n        \/\/ Capture the layout's TextView and set the string as its text\n        TextView textView = findViewById(R.id.textView);\n        textView.setText(message);\n\n\n\n    }\n}<\/pre>\n<pre>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The user interface for an Android app is built using a hierarchy of: Layouts (ViewGroup objects) are invisible containers that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[3,4,6,8],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-android-studio","tag-java","tag-programming"],"_links":{"self":[{"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nezis.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=42"}],"version-history":[{"count":5,"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/nezis.gr\/index.php?rest_route=\/wp\/v2\/posts\/42\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/nezis.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nezis.gr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nezis.gr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}