1 / 7

Android Activity Class (Android Activities)

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 ;

trixie
Download Presentation

Android Activity Class (Android Activities)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Activity Class (Android Activities) • Brugergrænseflade og brugeraktioner er en aktivitet // ** The ActivityClass ****************************************** // packagecom.paad.myapplication; import android.app.Activity; import android.os.Bundle; public classMyActivityextendsActivity { /** Calledwhen the activity is firstcreated. */ @Override public voidonCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); } } // ** Activity layout in XML <activity android:label="@string/app_name" android:name=".MyActivity"> </activity>

  2. 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 • MapActivty, List Activty, ExpandableListActivty og TabActivity • Tilstand styret af Android Framework. • Mange Activities i en applikation kan give behov for eget Application objekt. Screen Layout “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”.

  3. Klassehieraki

  4. 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” @Override public voidonCreate(Bundleicicle) { super.onCreate(icicle); TextViewmyTextView = new TextView(this); setContentView(myTextView); myTextView.setText("Hello, Android"); } @Override public voidonCreate(Bundleicicle) { super.onCreate(icicle); setContentView(R.layout.main); TextViewmyTextView = (TextView)findViewById(R.id.myTextView); }

  5. Layout hvordan XML og kode <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Enter Text Below" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Text Goes Here!" /> </LinearLayout> 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);

  6. Hvad er der så at holde styr på i GUI’en?http://developer.android.com/guide/topics/ui/index.html • View http://developer.android.com/reference/android/view/View.html • ViewGroup http://developer.android.com/reference/android/view/ViewGroup.html • Layout http://developer.android.com/reference/android/widget/LinearLayout.html • Widget Package http://developer.android.com/reference/android/widget/package-summary.html • Menu http://developer.android.com/guide/topics/ui/menus.html(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

  7. Event Listners • Inline Clas Implementation • Bruge “Implements” metoden • Bruge en variabel til en listner metode • XML attribute android:onClick="click1” • Sørg for at have en void click1(View v){ …} metode i Activity

More Related