Info

iit-yflinX'il^.^J Activity & Activity Diary Edit, XtftàM^M XftJS diary edit.xmlo *î M* ft l\\m\MT Li near Layouts Text View ill EditText.

<?xml versior.=" 1.0" encoding="uti-8"?> <Linearlayout.

xmins:Android="http://schémas.Android.com/apk, Android"

Android : orientâti on -"vertical" Android:layout _wadth-"fi11 parent" Android: layout height - "! i 1.1 parent">

<LinearLayout Android : orientation="vertica." Android:layout_width="FÏll parent" Android:layout height="wrap_content">

CTextView Android:layout width -"wrap_content" Android:layout_height="wrap_content" Android:text "@string/titie" Android : padding-"2px" /> <Kd.tText Android:[email protected]<id/title" Android: layout widt'n="fi 11 parent" Android:layouthei ght-"wrap_content" Android:layout weignt="l" /> < / L i n ea r La you t: >

<TextView Android :layout width="wrap_content"

Android: layout height-"wrap_content" Android : text="@st. rinq/body" /> <£ditText Android:id-"@* id/body" Android:layout_width=Mfill_parent" Android:layout height="wrap content" Android:layout weight="lM Android:scrollbars-"vertical" />

<Button Android:id="@+id/confirm" Android:text="@string/confirm" Androi d: 1a you L wi dth "wrap cont ent" Android:layout height="wrap_content" />

<\\ -^LinearLayout IfiiiiMJ/A'ii!! -^St*«, iAIKill Button m II-

fcfi^lMrfcJ. ^^iiiiW^mi^mj onclick 7/iJ..

RttttRfol KW/J V:

public void onClick(View view) { String title = mTitleText.getText().toString(); String body mBodyText.getText().toString<) ; if (mRowId != null) (

mDbHelper.updateDiary(mRowId, title, body); } else mDbHelper.createDiary(title, body) ; Intent mlntent = new Intent(); setResult(RESULT OK, mlntent); finish(); \

• IliiifmRowId % null, )f\WtMf mDbHelper.createDiary (title, body) WkhMlfcWiUff-M

mir'/u l:iMMmfc, ZMmVM ActivityMain, ifttfft on Activity Result, KMW

protected void onActivityResult (int requestCode, int resultCode, Intent intent) {

super.onActivityResult(requestCode, resultCode, intent); renderListView () ;

• F ActivityMain "VPift onListltemClick Ui&ttWk-.

protected void onListltemClick(Listview 1, View v, int position, long id) { super.onListltemClick(1, v, position, id); Cursor c mDiaryCursor; c.moveToPosition(position);

Intent, i new Intent (this, ActivityDiaryEdit.class) ; i.putExtra(DiaryDbAdapter.KEY R0WID, id); i.putExtra(DiaryDbAdapter.KEY TITLE, c.getStr i ng(c .getColumnlndexOrThrow(DiaryDbAdapter.KEY TTTLE))); i.putExtra(DiaryDbAdapter.KEY_BODY, c.getString(c .getColumnlndexOrThrow(DiaryDbAdapter.KEY BODY))); start Act .ivi tyForResul t (i, ACTIVITY EDIT); )

• c.moveToPosition (position) ififtj&d Cursor position ft'ft, imposition

• Intent i = new IntentCthis, ActivityDiaryEdit.class)i/HiJt^iS i^^Hi'J ActivityDiaryEdit EKi intent.

• putExtraintent

• c.getString (c.getColumnlndexOrThrow(DiaryDbAdapter.KEY TITLE)) + title fl'jfflo

• c.getString (c.getColumnlndexOrThrow(DiaryDbAdapter.KEY BODY)) & g^J body

• startActivityForResult (i, ACTIVITY EDIT) iftiiJA'i^I intent. Activity fftSMft.

• K ActivityDiaryEdit onCrcateQffi iMjfW:

Bundle extras get. Intent (). get Extras () ; if (extras != null) \

String title ext ras . get St ring (DiaryDbAdapter . KEYTITLE) ; String body = extras.getString(DiaryDbAdapter.KEY BODY); mRowId = extras.getLong(DiaryDbAdapter.KEY_R0W1D);

• M ]• ActivityDiaryEdit Aetivity WWI" intent nTfcJlBM£i4#, U U id WW IK. S^Bi« intent ftj&ffl extras » -^^iJMW IS, i^tlMMW intent m extras »|g. /fr^: ActivityDiaryEdit ^MlMvLPW extras jitf^ null, ijftnjy^-lj «JSflMt intent f^iWo

• s,'i extras null, fflft extras liiW»^ ^./Tm'IV^o

0 0

Post a comment