hi...am trying to delete a note in a note pad....the emulator works
fine and the delete button is created but does not perform any
action....below is my code:


public class NoteEdit extends Activity {

        private EditText mTitleText;
        private EditText mCommentText;
        private EditText mBodyText;
        private Long mRowId;

         private NotesDbAdapter mDbHelper;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            mDbHelper = new NotesDbAdapter(this);
        mDbHelper.open();

            setContentView(R.layout.note_edit);

            mTitleText = (EditText) findViewById(R.id.title);
            mCommentText = (EditText) findViewById(R.id.comment);
            mBodyText = (EditText) findViewById(R.id.body);

            Button confirmButton = (Button) findViewById(R.id.confirm);
            Button deleteButton = (Button) findViewById(R.id.menu_delete);

            mRowId = (savedInstanceState == null) ? null :
                (Long)
savedInstanceState.getSerializable(NotesDbAdapter.KEY_ROWID);

            if (mRowId == null) {
                Bundle extras = getIntent().getExtras();
                mRowId = extras != null ?
extras.getLong(NotesDbAdapter.KEY_ROWID)
                                        : null;
            }

            populateFields();

            confirmButton.setOnClickListener(new View.OnClickListener() {

                public void onClick(View view) {
                    setResult(RESULT_OK);
                    finish();
                }

            });

            deleteButton.setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                                // this is where am having problems ..dont know 
what how to set
the delete button.... its a text view and not a label

i used RESULT_CANCELED ..... did not work
                        }
                });

        }


        private void populateFields() {
            if (mRowId != null) {
                Cursor note = mDbHelper.fetchNote(mRowId);
                startManagingCursor(note);
                mTitleText.setText(note.getString(
        
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
                mCommentText.setText(note.getString(
 
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_COMMENT)));
                mBodyText.setText(note.getString(
        
note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
            }
        }

        @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(NotesDbAdapter.KEY_ROWID, mRowId);
    }

        @Override
    protected void onPause() {
        super.onPause();
        saveState();
    }

        @Override
    protected void onResume() {
        super.onResume();
        populateFields();
    }


         private void saveState() {
                String title = mTitleText.getText().toString();
                String comment = mCommentText.getText().toString();
                String body = mBodyText.getText().toString();

                if (mRowId == null) {
                    long id = mDbHelper.createNote(title,comment, body);
                    if (id > 0) {
                        mRowId = id;
                    }
                } else {
                    mDbHelper.updateNote(mRowId, title,comment, body);
                }
            }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to