X

0<h*r JnfOftnathMi

Ringione P Ii |i]|MBB| Send calls directly to voicemail.

0<h*r JnfOftnathMi

Ringione P Ii |i]|MBB| Send calls directly to voicemail.

a si 8-27 mm* (5) ftjffi KiÄWatfl^», «ft) 4. ^Htfr

Iii 8-28

Haiyang

Haiyang

Iceskysl

29 ^jlQE^i

fMm ■ K&Uf' ActivityMain 'T^J onCreate()/j vi, protected void onCreate(Bundle savedlnstanceState) { super.onCreate(savedlnstanceState);

Cursor c - getContentResolver() .quer y(Phones.CONTENT^ URI, null, null, null, null); startManagingCursor(c);

ListAdapter adapter = new SimpleCursorAdapter(this. Android.R.1ayout.simple_list item_2, c, new String[] { Phones.NAME, Phones.NUMBER }, new int|| { Android.R.id.textl, Android.R.id.text2 }); setListAdapter(adapter);

• getContentResolver() S'JKtfJIJ ffl ContcntResolver *

• query (Phones.CONTENTU R1, null, null, null, null). ContentResolver Uift timummx, cursoro H^mmw^xtw F.

• ffia^Jifilial Uri fiKJRAKl Uri.

• startManagingCursor(c)®'fij Cursor,.

• ListAdapter adapter = new SimpleCursorAdapter(this,Android.R.layout.simple list item 2, c, new String[] { Phones.NAME, Phones.NUMBER (, new int[] { Android.R.id.textl, Android.R.id.text2 \) i/KlJ^li^C SimpleCursorAdaptero ( & p SimpleCursorAdapter ftffJit® 7 J® Li ft iffl ^ 3J

• setListAdapter(adapter)o ListView ill SimpleCursorAdapter titfftftfeo 8.5.3 if ffl ContentProvider fcftSfcfiB

/i: I: • t tfij r- a 'tl ^ r ContentProvider. Jf- U ffi ffl / £ & rt' M - t tt £ A ftj

Jf] ContentProvider ifi] I'L^fU i* # Mfi! tf tt nf W ft f»J ®M Fl idt

• SEWUriMatcher WfrX.

• onPrepareOptionsMenu /jfiiYtU 0 1.

/): Eclipse 'I'fi H: ex09 2_contentProvider Jtfi i I, t^SSinT-

(1) frit " f-fiJi 11. ttc& ^ .li File - New - Android Project a

(2) /iiir^i® M ffiXi iSflHr|', Create project from existing source Jj/U

(3) ^SMJiLflS, ex09_2 ContentProvider « g , «Jg^iSfllSaffl,

«jrwsatiftttinw 8-31 rr^o 2.

^jtMirii^^11. Vtzmmm 8-32

; -:on eotAndroid cont«ntFr4Vi4*r

• Ui iryCoxittn'.Provsd«: • »v» « Android 1 I

• • :o«i eoefcndroid coat«tPr-JVi-i«r _ Ulttl

X d) «ry_J»st xni .» di»ry_rn» xni vtluui ■ im i nc; xnl Ci Andrei iWUr.i f »t« xol d»i»ul' pr«ptrW«i

1*1 8-32 8 JiMtt iffl.fif5JB.it. Activity t

ListActivity, diary list.xml, £ J'- ListActivity fM£J|J ii-?lfl«fcRIJ uf y.

#i*L35 7 6 iVo diaryJist.xml WWJiill

<?xml version=" 1.0" encodir.g="utf-8"?>

<LinearLayout xmlns:Android="http://senemas.Android.com/apk/res/Android" Ar.droid: 1ayout_width="wrap content" Android:layout height^"wrap_content">

<Li stView Android:id="@+id/Android:list" Android:layout width="wrap content" Android: layo.ut_height="wrap_content" /> <TextView Android:id="@+id/Android:empty" Android:layout_width="wrap content"

Android: layout height ="wrap_content" Android: text= B ir!«^ ! £ ifcTifcifi Menu tttfl ftte^nteW:)" />

Jt-'l' ListView W id miimmXhl Android:id= "@+id/Android:list", List

Activity aSlfflMflJ.

ContentProivder >t<;iJJtL«

ftff]5fc*# ->" Diary S^ffl&fj ^rt^f^^ DiaiyColumns, fn^^^^ES

-tt. 11'ui^mwmwirnm public static final class DiaryColumns implements BaseColumns { private DiaryColumns() {}

public static final Uri C0NTENT_UR1 = Uri .parse ("content://" + AUTHORITY + "/diaries") ; public static final String CONTENT TYPE = "vnd.Android.cursor.dir/vnd.google, diary"; public static final String CONTENT_ITEM_TYPE = "vnd.Android.cursor.item/vnd.

google. diary" ;

public static final String DEFAULT SORT ORDER = "created DESC"; public static final String TITLE = "title"; public static final String BODY "body"; public static final String CREATED = "created";

• BaseColumns Si ^h&P, fiiiYj'Pi^fit ^ii ID- " id", M —4wfe_COUNT=M count" o it Android "VP. -^»«Pf*«^ ifflfiii^^SfiJd. KW^ffilfjfi ift^iJ^WttiWj^Bi. BaseColumns , affftlflflEtt^»«^"!Jd ISo

• "id", "title" > "body"> "created"«

DiaryContentProvider li^äf.^Ö ContentProvider, #&>H§!tti4$iÄl f ContentProvidcr (ft P //?£, # R " t ContentProvider0 JÄ't*

3S, if-3H 7M$Ä~t fl & Xffo ContentProvider

C1 ) -ft/ft ContentProvider.DiaryContentProvider ContentProvider ^[ftc

(2) t- public static final (ft Uri CONTENT URlo Diary Content

Provider JjJrföÄbÄftj Uri CONTENT URI ^Jifcift. SJSii&MÄ, CONTENT URI

Kiift^^T + W ^WilURl, iaa^tTrii-tURI, nTW rw content URI iHjtlj/Ä, ft

content://com . ex09_2_conten tprov i de r . d.i. a r ycon t en tprov i de r /d i a r i. es / 3

• m -.ftä^JSiSIX (AUTHORITY) S|S ft, fffiii^S com.ex09_2_ content provider.diary contentprovider, fcj. ftfiUM' J'&JIMI" Content Provider IW^Ifc. ){ U^flS'Kf. ääÄBftSftft AndroidManifest.xml lft<provider Android:name -'DiaryContentProvider" Android:authorities="com.exO<> 2 contentprovider. diaryconten (provider" />

0 0

Post a comment