2015-02-07 56 views
-1
public void addup(UserProfile profile) 
{ 
    SQLiteDatabase db = this.getWritableDatabase(); 
    ContentValues values = new ContentValues(); 
    values.put("countrycode", profile.getCCode()); 
    values.put("deviceid",profile.getDID()); 
    values.put("devicename", profile.getDName()); 
    values.put("homeLoc",profile.getLat()+","+profile.getLong()); 
    values.put("mobile", profile.getMobileNum().toString()); 
    values.put("name",profile.getUName()); 
    values.put("password", profile.getPWD()); 
    values.put("uid", profile.getUID()); 
} 

我試過這個,但是每次使用時都放一個索引總是被新值替換。我曾嘗試使用ContenValues(8)將所有內容都設置在正確的位置,但同樣的情況再次發生。請幫忙在Android中使用ContentValues添加值時,下一個put方法會覆蓋已添加的值

+1

你認爲'addup'方法能做什麼? – iRuth 2015-02-07 11:20:20

+0

它被用來將行添加到sqlite數據庫。在使用put時,值會被添加到某個值中,並且一些值將被添加到同一個索引中,以替換舊的值,因此不會將舊值添加到數據庫中的列中。請幫忙。 – 2015-02-09 02:39:42

回答

0

您的addup方法缺少最終的數據庫插入語句。你應該修改你的addup方法,正如我在下面做的那樣。我假設你的表名叫做TABLE_DATA

public void addup(UserProfile profile) { 

    SQLiteDatabase db = this.getWritableDatabase(); 
    ContentValues values = new ContentValues(); 
    values.put("countrycode", profile.getCCode()); 
    values.put("deviceid",profile.getDID()); 
    values.put("devicename", profile.getDName()); 
    values.put("homeLoc",profile.getLat()+","+profile.getLong()); 
    values.put("mobile", profile.getMobileNum().toString()); 
    values.put("name",profile.getUName()); 
    values.put("password", profile.getPWD()); 
    values.put("uid", profile.getUID()); 

    /* insert row */ 
    long rowID = db.insert(TABLE_DATA, null, values); 

} 

讓我知道這是否有幫助。