Insert timestamp column in database android

  android

How do you insert another column, data/timestamp in a database and display it in the Listview existing in database android ? I have the code of my database here:

public class Helper extends SQLiteOpenHelper {
public static final String KEY_TIMESTAMP = "timestamp";

public Helper(Context context) {
    super(context, "ContactManager", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE contact(_id INTEGER PRIMARY KEY AUTOINCREMENT DEFAULT 1   ,nom TEXT, KEY_TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS contact");
    onCreate(db);
}

public void AddContact(int id , String nom , String dtNoteDay)
{
    SQLiteDatabase db=this.getWritableDatabase();
    SimpleDateFormat fmtDate = new SimpleDateFormat("YYYYMMdd hh:mm:ss");
    dtNoteDay = fmtDate.format(new Date());
    ContentValues cv=new ContentValues();
    Scanner s = new Scanner(nom);
    while (s.hasNextLine()){
        String line = s.nextLine().replaceAll("[^d]","") ;
        if (line.trim().length()>0) {
            cv.put("nom",line);
            cv.put("KEY_TIMESTAMP",dtNoteDay);
            db.insert("contact", null, cv);
        }
    }


}

Source: Android Questions

LEAVE A COMMENT