varsha valanju varsha valanju - 2 years ago 99
Android Question

working with custom views and sqlite database-android

I m working on password manager app.
in which I have created database with one table.


id, title, category, username, password, website, comment

And the main activity contains views for above fields.
but now I want to add a button called
"add filed"
through which user can add new view like one more username , or edittext for any other custom entry.

But the problem is...

How can I save those custom entries into database? Because, there may be a possibility that user want to add one custom entry for first password. and two custom entries for second password. so how can I manage those extra custom records into database.

plz help..

Answer Source

Use Alter Table query to add new field in table. For ex.,

 if (!isColumnExistInTableOrNot("entry", "username2" )) {
            db.execSQL("ALTER TABLE entry ADD COLUMN username2 varchar");


the isColumnExistInTableOrNot() is.

 public static boolean isColumnExistInTableOrNot(SQLiteDatabase db,String tableName,
                                                    String ColumnName) {
        String Query = "select " + ColumnName + " from " + tableName;
        try {
            Cursor c = db.rawQuery(Query, null);
            if (c != null) {
                return true;
        } catch (SQLiteException e) {
            return false;
        return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download