-1

I done coding on Database

public int updateContact(ModelContact modelContact) {

    SQLiteDatabase db = dbHelper.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(dbHelper.KEY_NAME, modelContact.getName());
    values.put(dbHelper.KEY_CONTACT, modelContact.getPhoneNumber());
    values.put(dbHelper.KEY_TYPE, modelContact.getType());


    return db.update(dbHelper.TABLE_CONTACTS, values, dbHelper.KEY_ID + " = ?",
            new String[] { String.valueOf(modelContact.getID()) });
}

Now what code i do onClick of update button in Activity.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

3 Answers3

0

  • if you increase the number of DATABASE_VERSION. It is going to be
    updated. DATABASE_VERSION = 2

  public class SqliteHelper extends SQLiteOpenHelper {  
        static final String DATABASE = "databasename"; 
        static final int DATABASE_VERSION = 1;
            public SqliteHelper(Context context) {
                    super(context, DATABASE, null, DATABASE_VERSION);
                }
    }
Samet ÖZTOPRAK
  • 3,112
  • 3
  • 32
  • 33
0

This code you can write in your activity class's update button on click method, this will work for you,

EditText nameEditText = (EditText) findViewById(R.id.name);
EditText phoneNumberEditText = (EditText) findViewById(R.id.phoneNumber);
EditText nameType = (EditText) findViewById(R.id.type);

ModelContact modelContact = new ModelContact();
modelContact.setName(nameEditText.getText().toString());
modelContact.setPhoneNumber(phoneNumberEditText .getText().toString());
modelContact.setType(nameType .getText().toString());

updateContact(modelContact);

Let me know if you need any other help.

Shivam
  • 702
  • 2
  • 10
  • 25
-1

Please check this link from another stack ;Android: upgrading DB version and adding new table

Basically you should update ur database version by assigning a greater number to static int.

private static final int DATABASE_VERSION = 4;

and then include it in your constructor.

MyOpenHelper(Context context) {

 super(context, "DatabaseName", null, DATABASE_VERSION);
}
Community
  • 1
  • 1