Mm m Action sftj Mmim Tffiii

Intent intento new Intent(this, ActivityDiaryEditor.class); intento.setAction(ActivityDiaryEditor.INSERT DIARY ACTION); intentO.setData(get Intent().getData()); startAct:ivity (intentO) ;

• M Mtíi.'fí'J intentO.setAction ( ActivityDiaryFditor.INSERT DIARY ACTION) i&îSfft action J¿ ActivityDiaryEditor.INSERT DIARY ACTION)'^»Wo

• ft. Activity Diary Editor »-I'M onCreate()i*i », L^fiU ActionINSERT DIARY ACTION MM. miMi mState = STATE INSERT, Ik^^feiil^nWlW&^ttAtt&o

• (Action) Ml EDIT_DIARY_ACTION, mState = STATE EDI To

IMf con firm Button Mtyrli&K W onCIick()rfi»c private void insertDiary() (

String title = mTitleText.getText().toString();

String body = mBodyText.getText().toStrina();

ContentValues values lr new ContentValues();

values.put(Diary.DiaryColuntns.CREATED, DiaryContentProvider

.getFormateCreatedDate 0) ;

values . put ( Diary . Diar yCeluiuns . TITLE, title) ; values.put(Di a ry. Di aryColumns.BODY, body);

getContentResolver().insert(Diary.DiaryColumns.CONTENT URI, values); I

• «FBttAWftlKffljttSiJ—t ContentValues ftJ3fe#n«t».

• $JJTJ getContentResolver()ffjiij tjij/S/iJ W ^ ContentResolver fi<J„

• insert (Diary. Diary Col umns. CON TENTURI, values) ContentResolver fftMi A

® ContentValues tWc DiaryContentProvider 'I'M insert()//&.

^^Sii^ScfflG, SJi-m^ihrnum 8-35

ft! 8-36 MENU «^»M IffiM*. h'lfii fi • hl'lfl^jftfi.

arctfiBiB

18 36 jg&MfNUtiMHii public boolean onPrepareOptionsMenu(Menu menu) i super.onPrepareOptionsMenu(menu);

final boolean haveltems - getListAdapter().getCount() > 0; if (haveltems) (

it (get. List View () . qet Select edit em Id () > 0) { menu.removeGroup <1);

Uri uri ContentUris.withAppendedld(getlntent().getData() , getSelectedltemld() ) ;

Intent intent = new Intent(null, uri);

menu.add(1, MENU ITEM EDIT, 1, . setlntent (intent) ;

menu.removeGroup(1); 1

return true; )

• ^Iliuilli^t List View ffi^RW ListAdapter iftih /¿4ifft^ft Afhaveltems

• menu.removeGroup(l), ftp» menu 1 fflffj J-flSWii.

• getIntent().getData()^flJM Uri & DiaryColumns.CONTENT URL

• ifi rl ContentUris.withAppendedId(getIntent().getData(),getSelectedItemld()) 'L ill ListView -JSWftftlW Uric

• menu.add(I, MENU ITEMEDIT, I, ?P).setIntent(intent), & menu 'Vt'JWJjII f J® "«»1*3 ft". Jt-fij* -J®in intent X-W, intent fe-Sffl F«fli»«. £!iA«iBrM«tJi ' t Uri [ft ftffi, A: KiMj onOptionsItemSelected()ft "'4 •f^JIJS'J.

• menu.addd, MENU ITEMDELETE, 1, "»JifcSM F1 id"), iWSnM^I—J®-

• M haveltems M*, ListView Hl^Kffr ListAdapter ^Ui/L^fft t ft Xl WttlKJ^ifc ListView hWB-m, ^ MENU ScfflWig, iP» menu 1 f

| »->MI onOptionsItemSelectedO, S tt&ffi iS + * £

: onPrepareOptionsMenu(),ii[^2ift£#^j£& MENU tytfe&Tf menu

: ## menu ft * ft* £ H iM jfc & ft. ilfl»ft j menu

MENU ft Itf Hi % 3 ^ft'ifl, ^¡frK + W*-^««^)!*»: Android onOptionsItemSelectedO^ft, fit {Will K0m<:

^Override public boolean onOptionsItemSelected (Menul tern item) ( switch (item.getltemld()) { //

case MENU_ITEM_INSERT:

Intent intentO = new Intent (this, ActivityDiaryEditor . class) ;

intentO.setAction(ActivityDiaryEditor.IN5ERT_DIARY_ACTI0N);

intent.O.setData(get Intent() .getData());

startActivity(intentO);

return true;

case MENU ITEM_EDIT:

Intent intent = new Intent(this, ActivityDiaryEditor.class); intent.setData(item.getlntent().getData()); intent.setAction(ActivityDiaryEditor.EDIT DIARY ACTION); startActivity(intent); return true; //

case MENU ITEM DELETE:

Uri uri = ContentUris.withAppendedld(getIntent{).getData(), getListView () . getSelectedl temld () ) ; getContentResolver().delete{uri, null, null); renderListView{);

0 0

Post a comment