Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 | 2010 Activity og GUI Android Brugergrænseflade.

Similar presentations


Presentation on theme: "1 | 2010 Activity og GUI Android Brugergrænseflade."— Presentation transcript:

1

2 1 | 2010 Activity og GUI Android Brugergrænseflade

3 2 | 2010 Android Application Class Svarer ”nogenlunde” til J2ME Midlet “Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, which will cause that class to be instantiated for you when the process for your application/package is created.” Kan håndterer onCreate, onTerminate, onLowMemory og onConfigurationChanged events

4 Eksempel Application class 3 | 2010 // ** The Application Class *************************************** // // ******************************************************************* // ** Listing 3-7: Skeleton application class // Appliction Class Extenstion import android.app.Application; import android.content.res.Configuration; public class MyApplication extends Application { private static MyApplication singleton; // Returns the application instance public static MyApplication getInstance() { return singleton; public final void onCreate() { super.onCreate(); singleton = this; } // Manifest entry [... Manifest nodes...]

5 4 | 2010 Android Activity Class (Android Activities) Brugergrænseflade og brugeraktioner er en aktivitet // ** The Activity Class ****************************************** // package com.paad.myapplication; import android.app.Activity; import android.os.Bundle; public class MyActivity extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } // ** Activity layout in XML

6 5 | 2010 Activity bruger View og Layout til UI og interaktion med brugeren Activity og Form svarer 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 MapActivty, List Activty, ExpandableListActivty og TabActivity Tilstand styret af Android Framework. Mange Activities i en applikation kan give behov for eget Application objekt. “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”. Screen Layout

7 6 | 2010 Klassehieraki

8 7 | 2010 Activity ->Layout-> View -> Widget &| ->UI Control View er adgangen til skærmressourcen på enheden Layout er manageren, der kontrollere View opsætningen Widget er en kontrol i View, og som ligner den rigtige verdens ting. Et ur eller et kompas. Kan også være et View UI control er grafiske enheder som knapper eller ”gestures” // ** Listing 4-1: Inflating an Activity public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); TextView myTextView = (TextView)findViewById(R.id.myTextView); } // ** Listing 4-2: Creating a UI layout in public void onCreate(Bundle icicle) { super.onCreate(icicle); TextView myTextView = new TextView(this); setContentView(myTextView); myTextView.setText("Hello, Android"); }

9 8 | 2010 Klassediagram Et eksempel Fra

10 9 | 2010 Layout hvordan XML og kode LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); TextView myTextView = new TextView(this); EditText myEditText = new EditText(this); myTextView.setText("Enter Text Below"); myEditText.setText("Text Goes Here!"); int lHeight = LinearLayout.LayoutParams.FILL_PARENT; int lWidth = LinearLayout.LayoutParams.WRAP_CONTENT; ll.addView(myTextView, new LinearLayout.LayoutParams(lHeight, lWidth)); ll.addView(myEditText, new LinearLayout.LayoutParams(lHeight, lWidth)); setContentView(ll);

11 10 | 2010 Hvad er der så at holde styr på i GUI’en? View ViewGroup Layout Widget Package Menu (Menu knappen) View properties: Statisk og/eller dynamisk. UI Events Define an event listener and register it with the View Override an existing callback method for the View (Custom Views) Menu Events

12 11 | 2010 Event Listners application/ application/ 1.Inline Clas Implementation 2.Bruge “Implements” metoden 3.Bruge en variabel til en listner metode 4.XML attribute android:onClick="click1” Sørg for at have en void click1(View v){ …} i Activity

13 12 | 2010 Event Listners application/ application/ 1.Inline Clas Implementation 2.Bruge “Implements” metoden 3.Bruge en variabel til en listner metode 4.XML attribute android:onClick="click1” Sørg for at have en void click1(View v){ …} i Activity

14 13 | 2010


Download ppt "1 | 2010 Activity og GUI Android Brugergrænseflade."

Similar presentations


Ads by Google