M Activity AMMffiM

Use Case « User fi-«A'AM7 User MfflIAfiSiM;Ml®ffi

AfJJMffllAfflA® User SifiSP' User MASPAMEffllAfiMA®

a«» ° -{@maaaaa{@®a • mi • -m Activity AMAAAAAfiff

5 ASAW^AAI rAffj fiMA : m User

Activity ASAfiAMl®m(Event Handler) Alt!

-m Use Case AAfAfflA^EfflfMAA^fi-ASi'M® uc: PickUp An Item A

[email protected]®{fAA#li [email protected]:g"pu_layout"fi{f^A»[email protected] Use Case AfiMfiSi^ I-mi'tetl uc: DisplayChoice [email protected]:^"ac01_layout"fi{f^AlEA°

7.1.2 Activity Mfti mmmm-B ■^mmmfiimmmmmMi-mrn^fi Activity ^Aaaa

U'-m Activity AAAffAffllffiAA°AASMAA^"ac01"fi Activity ASA AAlf ac01_layout AA'AAIf pu_layout

Android Layout)^

m°S-»^AAmfiAA(View, ® Button A) 'AAAALftA^SfiAi^'«-

Android ffi'S—S(Activity)IIJHf£S—fAtM(Activity)ftAMA°

Activity ASAAM ' AA#ffl uml fiJlgAH AAMAPIHfiSiAiI' A^IAHMfiMH ° MAHAA =

---- ffE 1.1 : faM ' ac01_layout ^SMMSMMM ° ---- ffE 2 : pressPickupAnItem()^M^»M±l& Menu Up

---- ffE 3 : pickUpAnItemO^TM#f£ pu_layout ListView m-irnm ° ^¡TOMM item itn^m^ °

Hello World, ac01

Item-1

Item-2

Item-3

ac01_layout

Step-1: MA Android MÄ ex01_07 = Step-2: MM Activity : ac01 •

package com.misoo.ex01_07; import android.app.Activity;

import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView;

import android.widgetAdapterView.OnItemQickListener;

public class ac01 extends Activity implements OnClickListener { private String[] data = {"Item-1", "Item-2", "Item-3"}; private Button btn, btn2;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); set_ac01_layout(); } public void set_ac01_layout() { setContentView(R. layout. acOl); btn = (Button)findViewById(R.id.pu_6in); btn. setOnClickListener(this); btn2 = (Button)findViewById(R.id.exi/_£in); btn2.setOnClickListener(this); } public void onClick(View v) {

if (v == btn) this.set_pu_layout(); if(v == btn2) this.finish(); } public void set_pu_layout(){

setContentView(R. lay out.pickup);

List View lv = (List View)findViewById(R.id. list);

Array Adapter<String> array Adapter

= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_l, data); lv.setAdapter(array Adapter); lv.setOnItemClickListener(listener);

OnItemClickListener listener = new OnItemClickListener() {

public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { set_ac01_layout();

TextView tv = (TextView)findViewById(R.id.iv); tv.setText("choice: " + data[arg2]);

<?xml verslon="l.0" encodlng="utf-8"?>

<LlnearLayout xmlns:androld="http://schemas.androld.com/apk/res/androld" androld:orlentatlon= "vertical" androld:layout_wldth="flll_parent" androld:layout_helght="wrap_content">

<TextVlew android:id= "@+ld/tv"

androld:layout_wldth="wrap_content" androld:layout_helght="wrap_content" androld:layout_marglnRlght="3dlp" android:text=" @strlng/dlalog" /> <Button androld:ld= "@+id/pu_btn"

androld:layout_wldth="wrap_content" androld:layout_helght="wrap_content" androld:layout_marglnRlght="3dlp" androld:text="@strlng/plckup" /> <Button androld:ld= "@+ld/exlt_btn"

androld:layout_wldth="wrap_content" android:layout_height="wrap_content" androld:layout_marglnRlght="3dlp" androld:text="@strlng/exlt" /> </LlnearLayout>

<?xml verslon="l.0" encodlng="utf-8"?>

<LlnearLayout xmlns:android="http://schemas.android.com/apk/res/android" androld:orlentatlon= "vertical" androld:layout_wldth="flll_parent" androld:layout_helght="flll_parent" > <TextView androld:layout_wldth="flll_parent" androld:layout_helght="wrap_content" androld:text="Hello World, ac0l" /> <LlstVlew androld:ld="@+ld/llst"

androld:layout_wldth="wrap_content" android:layout_height="wrap_content" /> </LlnearLayout>

1. ac01 im^Wl public void set_ac01_layout() { setContentView(R.layout. ac01);

public void set_pu_layout(){

setContentView(R.layout..pic^Mp);

^gf wz^mmmmmmmmffim r °

public void onClick(View v) {

3. pickup «mm ListView MMBWik ' MAfiPMAfnq onItemClick()

public void onItemClick( ) {

set_ac01_layout();

mm ' f^ set_ac01_layout()®^ > IM®^ ac01_layout «mfflMr °

4. AffiMSAr-fiSAmgA :

Step-1 Step-2 Step-3

Mrn-fi Activity

«MfifMA ' ^ Use Case fJg^ Android m Activity imi^Hr

AffiMAWMM.xml mm- acQi.xml ffi pickup.xml

7.2.2 Activity Mfti :

smzm' Activity m^'mn^mrn ft acQ1

MMMAH(Sequence Diagram)^±—ffiMftJ®ffiW^—iT ' KMMHI Smft Android

H 7-3 Mffl Use Case M^^IliM

---- 1 = create()AAM#MfMAB#'MM Android gM!lA®M)ac01

set_ac01_r_layout() 'MMSAAAffftl rel_layout l liffiM0

A"pressPickupAnItem"^"pickup an ---- ac01 pickup an item l^'AfAM! item

m 1 ffl Use Case W^I&MfflffiffiWm 2 ffl Use Case mWM ListView g

Item-3

Step-1: Android ex01_08 =

package com.misoo.ex01_08;

import android.app.Activity;

import android.content.Context;

import android.graphics.Color;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.AdapterView;

import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView;

import android.widget.AdapterView.OnItemClickListener;

public class ac01 extends Activity implements OnClickListener { private String[] data = {"Item-1", "Item-2", "Item-3"}; private Button btn, btn2; private ListView lv;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); set_ac01_r_layout();

private void set_ac01_r_layout() {

RelativeLayout rel_layout = new RelativeLayout(this); setContentView(rel_lay out);

LayoutInflater inflate = (LayoutInflater) getSystemService(

Context.LAYOUTINFLATERSERVICE); LinearLayout layout = (LinearLayout)

inflate.inflate(R.layout.acOi, null);

layout setId(1);

RelativeLayout.LayoutParams rel_param = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams. WRAPCONTENT, RelativeLayout.LayoutParams. WRAP_CONTENT); rel_lay out. add View (layout, rel_param);

btn = (Button)findViewById(R.idpu_6in); btn. setOnClickListener(this); btn2 = (Button)findViewById(R.id.exi/_6/n); btn2. setOnClickListener(this);

LinearLayout layout_p = (LinearLayout)

inflate.inflate(R.layoutpickup, null); layout_p.setId(2);

rel_param = new RelativeLayout.LayoutParams(

RelativeLayout.LayoutParams. WRAP_CONTENT, RelativeLayout.LayoutParams. WRAPCONTENT); rel_param. addRule(RelativeLay out. RIGHTOF, 1); rel_layout. addView(layout_p, rel_param); lv = (ListView)layout_p.findViewById(R.id.list); Array Adapter<String> array Adapter = new ArrayAdapter<String>(this, android.R. layout. simple_list_item_1, data); lv. setAdapter(array Adapter); lv. setOnltemClickListener(listener);

public void onClick(View v) {

if (v == btn) lv.setBackgroundColor(Color.BZUE); if(v == btn2) this.finish();

OnItemClickListener listener = new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { TextView tv = (TextView)findViewByld(R.id.tv); tv.setText("choice: " + data[arg2]);

lv.setBackgroundColor(Color.D^GRAT); }

Step-3: ^M/res/layout/ac01.xml IfaA :

Step-4: ^M/res/layout/ac01.xml IfaA :

KftAKi-ffiMTO°

1. affiMI ac01.xml m pickup.xml miS^I^A^A-ffiMAA^! °

RelativeLayout rel_layout = new RelativeLayout(this);

AÄ^Am RelativeLayout ffMAAA ac01.xml pickup.xml AÄmfM °

Layoutlnflater inflate = (Layoutlnflater) getSystemService( Context.LAYOUTINFLATERSERVICE); LinearLayout layout = (LinearLayout)inflate.inflate(R.layout.ac07, null, null);

rel_layout.addView(layout, rel_param);

^fö» ac01.xml lAAMtlAA layout ffM ' Äföft layout ffMiPA» Am rel_layout ffMffi °

4. = LinearLayout layout_p

= (LinearLayout)inflate.inflate(R.layout.^ic^wp, null, null);

rel_layout.addView(layout_p, rel_param);

AföS pickup.xml mATOHAA layout_p ffM ' layout_p ffMJPA

a^Am rel_layout fMffi ° A^fMftxml A»mfMBAffiAA ° ♦

msm Mmsw^ÑmmmsQLite 193

0 0

Post a comment