Android Programming Lecture 4 Activity,Intent and Ul
Android Programming Lecture 4 Activity, Intent and UI
package com.example.editgreeting; import android.app.Activity; Superclass public class MainActivity extends Activity EditText e; TextView t; Button b; protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstancestate); setContentview(R.layout.activity_main); e =(EditText)findViewById(R.id.myEditText); t (Textview)findViewById(R.id.myTextView); b (Button)findViewById(R.id.myButton); Constructor b.setonclickListener(new MyButtonOnclickListener(); class MyButtonOnclickListener implements onclickListener @Override Interface Inner class public void onclick(View v){ /TODO Auto-generated method stub t.setText(e.getText());
2 Superclass Interface Constructor Inner class
RoadMap and Learning Objectives Learn to use the basic Ul widgets Learn to switch Activities using Explicit Intent 3
RoadMap and Learning Objectives • Learn to use the basic UI widgets • Learn to switch Activities using Explicit Intent 3
UI Development
UI Development 4
Basic Input Controls Input controls are used ▣ Button to take data from user ☑ o Widgets Text field OFF -TextView ON ■Button CheckBox -RadioButton Button Smal o年 CheckBox RadioButton Spinner CheckedTextView Spinner o Text Fields o Dialogs 6
Basic Input Controls • Input controls are used to take data from user o Widgets ▪ TextView ▪ Button ▪ CheckBox ▪ RadioButton ▪ Spinner o Text Fields o Dialogs 5
Text Fields Text Fields allow users to type text in your application. abe Text Fields have different types like: Firstname Lastname o Plain Text 白Form Widgets 321 Text Fields user@domain o Person Name I Plain Text 555)0100 IPerson Name o Password I Password Address I Password(Numeric) o Email IE-mail I Phone Lorem ipsum dolor sit amet consectetur o Phone I Postal Address rMultiline Text o Postal Address 1200am I Time I Date 1/n/2011 o Multiline Text INumber I Number(Signed) o Time 42 I图Number(Decimal) 42.0 o Date a AutoCompleteTextView AutoComplete a:MultiAutoCompleteTextView MultiAutoComplete o Number(Signed/Unsigned) All of the Text Fields mentioned above are merely attributes of EditText http://developer.android.com/guide/topics/ui/controls/text.html
Text Fields • Text Fields allow users to type text in your application. • Text Fields have different types like: o Plain Text o Person Name o Password o Email o Phone o Postal Address o Multiline Text o Time o Date o Number (Signed/Unsigned) • All of the Text Fields mentioned above are merely attributes of EditText 6 http://developer.android.com/guide/topics/ui/controls/text.html
Text View TextView is used to display text on screen. ia751 EditGreeting o EditText,Button are direct subclasses of Hello World TextView. TextView doesn't allow editing in itself It works more like a label Click me! ◆ 与 http://developer.android.com/reference/android/widget/TextView.html 7
Text View • TextView is used to display text on screen. o EditText, Button are direct subclasses of TextView. • TextView doesn't allow editing in itself • It works more like a label 7 http://developer.android.com/reference/android/widget/TextView.html
Buttons Buttons allows user to perform some action. Android have following button types available,sequence is Control Name(Class Name): o Button (Button) Off On o Image Button(ImageButton) o Toggle Buttons (ToggleButton) ATTENDING? o Radio Buttons (RadioButton) OYes OMaybe ONo All buttons have different classes and XML tags to represent them unlike the Text Fields (That had only one tag i.e.EditText) http://developer.android.com/guide/topics/ui/controls/button.html
Buttons • Buttons allows user to perform some action. • Android have following button types available, sequence is Control Name (Class Name): o Button (Button) o Image Button (ImageButton) o Toggle Buttons (ToggleButton) o Radio Buttons (RadioButton) • All buttons have different classes and XML tags to represent them unlike the Text Fields (That had only one tag i.e. EditText) 8 http://developer.android.com/guide/topics/ui/controls/button.html
ImageView ImageView is used to display an image. Practise3 ● Can load images from various BEEN THERE sources,e.g.,drawables/content providers. Various other display options available like scaling tinting. DONE THAT! 9
ImageView • ImageView is used to display an image. • Can load images from various sources, e.g., drawables/content providers. • Various other display options available like scaling & tinting. 9
Packages T□pp com.example.android.lifecycle P回tet 白u R.java ActivityA ©Activity8 ©a ActivityC BuildConfig ©DialogActivity ER R.java:hook the resources and java by P▣drawable--hdpi ▣drawable-ldpi P▣drawable-mdpi providing each resource item an ID 回drawable-xhdpi P▣layout y回values Reference a resource in Java codes Libraries [.]R.. o :name of the package in which the resource is located (not required when referencing resources from your own package). o :resource type. o :the resource filename without the extension or the android:name attribute value in the XML element. findViewById(R.id.***)identify a view on XML by its id ● setContentView(R.layout.***)apply the layout for the content view 0
• Reference a resource in Java codes o : name of the package in which the resource is located (not required when referencing resources from your own package). o : resource type. o : the resource filename without the extension or the android:name attribute value in the XML element. R.java • R.java: hook the resources and java by providing each resource item an ID 10 [.]R.. • findViewById(R.id.***): identify a view on XML by its id • setContentView(R.layout.***): apply the layout for the content view