Android Activity Class Android Activities l Brugergrnseflade og
Android Activity Class (Android Activities) l Brugergrænseflade og brugeraktioner er en aktivitet // ** The Activity Class ********************* // package com. paad. myapplication; import android. app. Activity; import android. os. Bundle; // ** Activity layout in XML <activity android: label="@string/app_name" android: name=". My. Activity"> </activity> public class My. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); } }
Activity bruger View og Layout til UI og interaktion med brugeren • Activity og Form kan ofte svare til hinanden: Præsentere et skærmbillede 1: 1 • Activity bruger Views, Layout og Widgets/Controls (Standard eller egne) • Der findes en sæt af specielt designede Activities i forhold til standard widgets • Map. Activty, List Activty, Expandable. List. Activty og Tab. Activity • Tilstand styret af Android Framework. • Mange Activities i en applikation kan give behov for eget Application objekt. Screen Layout 2 | 2010 “This hierarchy tree can be as simple or complex as you need it to be, and you can build it up using Android's set of predefined widgets and layouts, or with custom Views that you create yourself”.
Klassehieraki 3 | 2010
Activity ->Layout-> View -> Widget &| ->UI Control l View er adgangen til skærmressourcen på enheden l Layout er manageren, der kontrollere View opsætningen l Widget er en kontrol i View, og som ligner den rigtige verdens ting. Et ur eller et kompas. Kan også være et View l UI control er grafiske enheder som knapper eller ”gestures” @Override public void on. Create(Bundle icicle) { super. on. Create(icicle); set. Content. View(R. layout. main); Text. View my. Text. View = (Text. View)find. View. By. Id(R. id. my. Tex t. View); } @Override public void on. Create(Bundle icicle) { super. on. Create(icicle); Text. View my. Text. View = new Text. View(this); set. Content. View(my. Text. View); my. Text. View. set. Text("Hello, Android"); }
Layout hvordan XML og kode <? xml version="1. 0" encoding="utf-8"? > <Linear. Layout xmlns: android="http: //schemas. android. com/apk/res/android" android: orientation="vertical" Linear. Layout ll = new Linear. Layout(this); android: layout_width="fill_parent" ll. set. Orientation(Linear. Layout. VERTICAL); android: layout_height="fill_parent"> <Text. View android: layout_width="fill_parent" Text. View my. Text. View = new Text. View(this); Edit. Text my. Edit. Text = new Edit. Text(this); android: layout_height="wrap_content" android: text="Enter Text Below" /> my. Text. View. set. Text("Enter Text Below"); my. Edit. Text. set. Text("Text Goes Here!"); <Edit. Text android: layout_width="fill_parent" int l. Height = Linear. Layout. Params. FILL_PARENT; android: layout_height="wrap_content" int l. Width = Linear. Layout. Params. WRAP_CONTENT; android: text="Text Goes Here!" /> </Linear. Layout> ll. add. View(my. Text. View, new Linear. Layout. Params(l. Height, l. Width)); ll. add. View(my. Edit. Text, new Linear. Layout. Params(l. Height, l. Width)); set. Content. View(ll);
Hvad er der så at holde styr på i GUI’en? http: //developer. android. com/guide/topics/ui/index. html l View. Group http: //developer. android. com/reference/android/view/View. Group. html l Layout http: //developer. android. com/reference/android/widget/Linear. Layout. html l Widget Package http: //developer. android. com/reference/android/widget/package- http: //developer. android. com/reference/android/view/View. html summary. html l Menu http: //developer. android. com/guide/topics/ui/menus. html l View properties: Statisk og/eller dynamisk. l UI Events (Menu knappen) l Define an event listener and register it with the View l Override an existing callback method for the View (Custom Views) l Menu Events
Event Listners 1. 2. 3. 4. Inline Clas Implementation Bruge “Implements” metoden Bruge en variabel til en listner metode XML attribute android: on. Click="click 1” • Sørg for at have en void click 1(View v){ …} metode i Activity
- Slides: 7