TitleEditorpublic class TitleEditor extends android.app.Activity implements View.OnClickListenerAn activity that will edit the title of a note. Displays a floating
window with a text field. |
Fields Summary |
---|
public static final String | EDIT_TITLE_ACTIONThis is a special intent action that means "edit the title of a note". | private static final String[] | PROJECTIONAn array of the columns we are interested in. | private static final int | COLUMN_INDEX_TITLEIndex of the title column | private android.database.Cursor | mCursorCursor which will provide access to the note whose title we are editing. | private android.widget.EditText | mTextThe EditText field from our UI. Keep track of this so we can extract the
text when we are finished. | private android.net.Uri | mUriThe content URI to the note that's being edited. |
Methods Summary |
---|
public void | onClick(android.view.View v)
// When the user clicks, just finish this activity.
// onPause will be called, and we save our data there.
finish();
| public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.title_editor);
// Get the uri of the note whose title we want to edit
mUri = getIntent().getData();
// Get a cursor to access the note
mCursor = managedQuery(mUri, PROJECTION, null, null, null);
// Set up click handlers for the text field and button
mText = (EditText) this.findViewById(R.id.title);
mText.setOnClickListener(this);
Button b = (Button) findViewById(R.id.ok);
b.setOnClickListener(this);
| protected void | onPause()
super.onPause();
if (mCursor != null) {
// Write the title back to the note
ContentValues values = new ContentValues();
values.put(Notes.TITLE, mText.getText().toString());
getContentResolver().update(mUri, values, null, null);
}
| protected void | onResume()
super.onResume();
// Initialize the text with the title column from the cursor
if (mCursor != null) {
mCursor.moveToFirst();
mText.setText(mCursor.getString(COLUMN_INDEX_TITLE));
}
|
|