Menu fu starActivity

MM Use Case A^AAW (include)M# ' MAAAA^ffl Use Case ftfÎMAiM^ ' AA^A-ffl Use Case ftfiMAiM ° —Sm^KM Use Case ^

^MIH&^MM^ ' MIH&^MIB^ÊS—M Use Case ^ ' MA« rS

^ Use Case j (Base Use Case) ' ffAISM r AA Use Case j (Inclusion Use Case) °

MU ' MAS^ Use Case AlAAAMA Use Case ' MAAAA^ft Use Case H ' AlTOMMB«^ Use Case AWftffl^fÎMAiM T ° Use Case :

^KHÊIS® Activity îmm : AUA^MAM BaseActivity m InclusionActivity ' AAÎf—fSlWÎM ° ' BaseActivity ft1®A® User 5 KMM^ ' AAWg^ft startActivity()®^A^K InclusionActivity ' MSA—f® 1MÎM ' MM Inclusion Use Case ftS^MM ' InAAfâ^M®^ BaseActivity ftiffi ' mmW^ftKmmM ° MU ' A Android MAMAAAffiM Use Case

Use Case M3—M1BM ° MM—i®AM"pu_layout"ftf^MA»TOή Use Case AMftSMM ° M ' Aiffi uc: DisplayChoice MSffl—MAM "ac01_layout"ftf^MAfÎJSA °

Activity ac01_layout ffiM ° M ' Aiffi pu_layout

Activity AmmrajSA °

Activity ymmAik • uml mm^rn

(Sequence Diagram)AMMPIHm5^fM ' itM^ffiWmMH ° $PTH :

Sharedpreferences Uml

H 6-2 ^ UML mre^HA^ Andriod fMAfifUMmMH =

---- 2 : pressPickupO^^M^TM±lft Menu ^MM<Pick Up An

Item>MM - faM ' ac01 ^friffll^f^ Android g^ffilft startActivityO® »&®£(^M)pickup Activity ' fSfUMS

---- 3 : pickUpAnItemO^AM^T pu_layout Menu Hffi!®-

SharedPreferences ifrffiffi ' AfMSitln ac01 ifr = ---- 4 : pressShowResult()Menu ^MM<Show

Result>MM - faM ' ac01 ifrifflW SharedPreferences fflft '

a pickup mfrffiwftftfflmmrn- • °

2. MMM<Pick Up An Item>MM ' iffl^ii pu_layout ' :

3. :

acOl choice: item-3

6. rn^miimmm^r

Step-1: Android ex01_01 =

package com.misoo.ex01_01;

import android.app.Activity;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.view.Menu;

import android.widget.TextView;

public class ac01 extends Activity {

public static final int PICKUPID = Menu.FIRST; public static final int SHOWID = Menu.FIRST + 1; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout./wain); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, PICKUP ID, "Pick Up An Item"); menu.add( 1, SHOW ID, "Show Result"); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case PICKUPID:

Intent in = new Intent(ac01.this, pickup.class); startActivity(in); return true; case SHOWID:

SharedPreferences passwdfile = getSharedPreferences( "ITEM", 0); String im = passwdfile.getString("ITEM", null); TextView tv = (TextView)findViewById(R.id.iv); tv.setText("choice: " + im); return true; } return super.onOptionsItemSelected(item);

package com.misoo.ex01_01;

import android.app.Activity;

import android.content.SharedPreferences.Editor;

import android.os.Bundle;

import android.view.Menu;

public class pickup extends Activity {

public static final int ITEM1ID = Menu.FIRST; public static final int ITEM_2_ID = Menu.FIRST + 1; public static final int ITEM3ID = Menu.FIRST + 2; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout./wain); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, ITEM1ID, 0, "item-1"); menu.add(0, ITEM2ID, 1, "item-2"); menu.add(0, ITEM 3 ID, 2, "item-3"); return true; }

@Override public boolean onOptionsItemSelected(Menu.Item item) { Editor passwdfile = getSharedPreferences("ITEM", 0).edit(); passwdfile .putString("ITEM" ,item.getTitle(). to String()); passwdfile.commit(); finish();

return super.onOptionsItemSelected(item);

0 -1

Post a comment