Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:25:12+00:00 2026-05-20T18:25:12+00:00

hi i am an SEO and i am in currently practicing android development of

  • 0

hi i am an SEO and i am in currently practicing android development of my own. i studied about database storing in android developers site and found an example code that to be in a notepad.

I tried using it in my project. In my project i have placed 2 edit boxes with a OK button, when the OK button is clicked the data in the edit box gets stored and it is shown in a new page.

the following is the code of my project’s main class file,

{

    b = (Button)findViewById(R.id.widget30);

    et1 = (EditText)findViewById(R.id.et1);
    et2 = (EditText)findViewById(R.id.et2);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String title = extras.getString(NotesDbAdapter.KEY_ET1);
        String body = extras.getString(NotesDbAdapter.KEY_ET2);
        mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);

        if (title != null) {
            et1.setText(title);
        }
        if (body != null) {
            et2.setText(body);
        }
    }

    b.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            if(et1.getText().toString().length() == 0 && et2.getText().toString().length() == 0)
            {
                et.setVisibility(View.VISIBLE);
                alertbox();
            }
            else
            {
            main.this.finish();
            Intent myIntent = new Intent(v.getContext(), T.class);
             startActivityForResult(myIntent, 0);
            }
        }               
    });
}


public void alertbox() 
{
    et = new TextView(this);
    Builder alert =new AlertDialog.Builder(main.this);
    alert.setTitle("Alert");
    alert.setMessage("Required all fields");
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
    {
         public void onClick(DialogInterface dialog, int whichButton)
         {
            dialog.cancel();
         }
    });
    AlertDialog alert1 = alert.create();
    alert1.show();
}

}

the following is the code of the DataBaseAdapter

public class NotesDbAdapter {

    public static final String KEY_ET1 = "a";
    public static final String KEY_ET2 = "b";
    public static final String KEY_ROWID = "_id";

    private static final String TAG = "NotesDbAdapter";
    private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;
    private static final String DATABASE_CREATE =
        "create table notes (_id integer primary key autoincrement, "
        + "title text not null, body text not null);";

    private static final String DATABASE_NAME = "data";
    private static final String DATABASE_TABLE = "notes";
    private static final int DATABASE_VERSION = 2;

    private final Context mCtx;

    private static class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {

            db.execSQL(DATABASE_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("DROP TABLE IF EXISTS notes");
            onCreate(db);
        }
    }


    public NotesDbAdapter(Context ctx) {
        this.mCtx = ctx;
    }


    public NotesDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    public void close() {
        mDbHelper.close();
    }



    public long createNote(String a, String b) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_ET1, a);
        initialValues.put(KEY_ET2, b);

        return mDb.insert(DATABASE_TABLE, null, initialValues);
    }


    public boolean deleteNote(long rowId) {

        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }


    public Cursor fetchAllNotes() {

        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_ET1,
                KEY_ET2}, null, null, null, null, null);
    }


    public Cursor fetchNote(long rowId) throws SQLException {

        Cursor mCursor =

            mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                    KEY_ET1, KEY_ET2}, KEY_ROWID + "=" + rowId, null,
                    null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }


    public boolean updateNote(long rowId, String a, String b) {
        ContentValues args = new ContentValues();
        args.put(KEY_ET1, a);
        args.put(KEY_ET2, b);

        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
    }
}

when i run the project the new page is opening but the data’s entered is not shown there.

what is to be the error. pls teach me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:25:12+00:00Added an answer on May 20, 2026 at 6:25 pm

    You are going to need to get an instance of your database adapter

    NotesDbAdapter adapter = new NotesDbAdapter(this); //pass activity context as a param
    

    then you need to use the open method of the new database object to open the database

    adapter.open();
    

    now call the store method

    String str = myEditText.getText().toString();
    String str1 = "random other string";
    adapter.createNote(str, str1);
    

    I notice that your createNote method takes two params. I dont know where you want to get the other data from, so I just used ‘random other string’. Sub in the data you want to store as appropriate.

    Finally you will need to close the database:

    adapter.close();
    

    And you have successfully stored the information. See this for help on how to use the console to view the data that you have entered into the database. (See specifically the sqlite3 portion of the page) Alternatively you could write some code to display it on the screen after retrieving it. You are going to need to read about cursors if you want to retrieve info. See here for some information on that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are re-platforming for a client, and they are concerned about SEO. Their current
In SEO people talk a lot about Google PageRank . It's kind of a
I am looking for url encoding tips for SEO compliant site. I have a
Currently we are using method_missing to catch for calls to SEO friendly actions in
hi I am currently working on improving the SEO on a website containing dropdown
Our SEO team would like to open up our main dynamic search results page
We have an SEO team at my office, and one of their dictums is
What do you think is the best way to create SEO friendly URLs (dynamically)
Does filling out HTML meta description/keyword tags matter for SEO?
I am a bit stuck on the design of my seo friendly urls for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.