Listing 913 srccomcookbookdatastorageDiaryjava

package com.cookbook.datastorage;


import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;


public class Diary extends Activity { EditText titleET, contentET; Button submitBT;

MyDB dba;

^Override public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState); setContentView(R.layout.diary); dba = new MyDB(this);;

titleET = (EditText)findViewById(; contentET = (EditText)findViewById(; submitBT = (Button)findViewById(; submitBT.setOnClickListener(new OnClickListener() { public void onClick(View v) { try {

saveItToDB(); } catch (Exception e) { e.printStackTrace();

public void saveItToDB() {

dba.insertdiary(titleET.getText().toString(), contentET.getText().toString());



Intent i = new Intent(Diary.this, DisplayDiaries.class); startActivity(i);

The class is the same as in Listing 9.6 with the MyPreferences.class changed to launch the Diary.class when the login is successful:

Toast.makeText(DataStorage.this, "login passed!!",

Toast.LENGTH_SHORT).show(); Intent i = new Intent(DataStorage.this, Diary.class); startActivity(i);

Finally, the AndroidManifest XML file must be updated to include the new activities, as shown in Listing 9.14.

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment