Demo a7:51 dit Greeting Hello worle Click mel 11
Demo 11
Create a project, and open the layout xml file to make the layout as follows D HelloJava java团 MainActivity. java国' activity_mainxml8 ·0 Nexus One·8·★ AppTheme.@(activityClass) 19 us palette Form Widgets Ab TextView Ab Large Text Ab Medium Text Ab Small Text ox Button al Edit Greeting TextView ox)Small Button RAdiobUtton Hello world! ca CheckedTetView Spinner EditText a Progress Bar( Large) a ProgressBar(Normal) OuirkContactRarne Text Fields Button Click mel Time Date OOther O Custom Library Views a Graphical Layout B) activity.main xml a Problems Javadoc e Declaration B Console X 6 Progress BD LogCat 2 Lint Warnings <terminated> HelloJava ()[ava Application) C: Program Files Vava'yreB\bin\javaw. exe(04/08/2014: 05: 56 PM) Hello Java! 12
12 Create a project, and open the layout xml file to make the layout as follows. TextView EditText Button
<reLativelayoutxmins:android="http://schemas.androidcom/apk/res/android xmins:tools="http://schemas.androidcom/tools android: layout width="match _ parent android: layout height="match_ parent tools: context="srelativePackage) sactivityclass"> <Button android: id="+id/myButton android: layout width="wrap content Create an id for the button android: layout height="wrap content android: layout alignParentBottom="true Edittext and Textview android: layout centerHorizontal="true android: layout marginBottom="122dp respectively android: text="CLick me!"/> <EditText This is by specifying the android: id=e+id/myEditText android: layout width="match parent android id attribute, with android: layout height="wrap content android: layout above="@+id/myButton formate“@+id/anld android: layout alignParentLeft="true android: layout marginBottom="91dp android: ems= 10> You can arbitrarily name the <requestFocus / id but make sure that the id </EditText> Is unique <Textview android: id=@+id/my Textview android: layout width="wrap content android: layout height="wrap content android: layout above=G+id/myEditText android: layout centerHorizontal="true android: layout marginBottom="60dp android: text="Gstring/hello world"/> </RelativeLayout> 13
13 Create an id for the Button, EditText and TextView, respectively. This is by specifying the android:id attribute, with formate “@+id/anId” You can arbitrarily name the id, but make sure that the id is unique
Open the MainActivity java file in the java directory. The codes look like below Android w 8+I*.I C. java x o activity. main xml x D□ manifests package com. example. toml. editgreeting a com. example. tomL. editgreeting s acom. example. tom. editgreeting(androidTest a drawable a public class MainActivity extends Activity v layout e activity_mainXr oVerride □ protected void onCreate(Bundle savedInstanceState)( C Gradle Scripts super onCreate(savedInstanceState) setContentView(R layout. activity main) This is created automatically by the template. You may have more codes over there. If that is the case, no worries. You probably just adopt another template and it is also going to work In the next slides, we are going to elaborate on the codes 14
14 Open the MainActivity.java file in the java directory. The codes look like below. This is created automatically by the template. You may have more codes over there. If that is the case, no worries. You probably just adopt another template and it is also going to work. In the next slides, we are going to elaborate on the codes
This defines a package, and include your Main activity class in the package My project is named as Edit Greeting So the package name is com.example. editgreeting. You may have different package name here as you use another project name Can you roughly guess the directory of your Main Activity. java file based on the package name package com. example. editgreeting import android app. Activity;l public class MainActivity extends Activity t @Override protected void onCreate(Bundle savedInstanceState)t super onCreate(savedInstancestate); set ContentView(Rlayout activity main); Do you have an idea why we use a reversed order of the organization for the package name? 15
15 This defines a package, and include your MainActivity class in the package. My project is named as EditGreeting. So the package name is com.example.editgreeting. You may have different package name here as you use another project name. Can you roughly guess the directory of your MainActivity.java file based on the package name? Do you have an idea why we use a reversed order of the organization for the package name?