FileDocCategorySizeDatePackage
TitleEditor.javaAPI DocAndroid 1.5 API3471Wed May 06 22:41:08 BST 2009com.example.android.notepad

TitleEditor

public class TitleEditor extends android.app.Activity implements View.OnClickListener
An 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_ACTION
This is a special intent action that means "edit the title of a note".
private static final String[]
PROJECTION
An array of the columns we are interested in.
private static final int
COLUMN_INDEX_TITLE
Index of the title column
private android.database.Cursor
mCursor
Cursor which will provide access to the note whose title we are editing.
private android.widget.EditText
mText
The EditText field from our UI. Keep track of this so we can extract the text when we are finished.
private android.net.Uri
mUri
The content URI to the note that's being edited.
Constructors Summary
Methods Summary
public voidonClick(android.view.View v)

        // When the user clicks, just finish this activity.
        // onPause will be called, and we save our data there.
        finish();
    
public voidonCreate(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 voidonPause()

        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 voidonResume()

        super.onResume();

        // Initialize the text with the title column from the cursor
        if (mCursor != null) {
            mCursor.moveToFirst();
            mText.setText(mCursor.getString(COLUMN_INDEX_TITLE));
        }