2017-05-12 7 views
0

SQLテーブル内の列を(「クリック」)更新したいと思います。私はデバッグで行を見ることができますが、認識されません。SQL in android dosent work

click==0の場合はclick==1に変更してください。

誰かが私の間違いを知っていますか?

私のコードは次のとおりです。

public void UpdateClicked2(String name, int table) { 
    ContentValues values = new ContentValues(); 
    String selectQuery = "SELECT * FROM " + MySQLiteGUESTS.TABLE_NAME 
    + " WHERE " + MySQLiteGUESTS.COLUMN_TABLE + "=" + table; 

    Cursor cursor = database.rawQuery(selectQuery, null); 

    cursor.moveToFirst(); 
    while (!cursor.isAfterLast()) { 
    GuestInfo comment = cursorToComment(cursor); 
    if (comment.getName().toString() != name) 
     cursor.moveToNext(); 
    else { 
     if (comment.getClick() == 1) { 
     values.put(MySQLiteGUESTS.COLUMN_CLICK, 0); 
     } else 
     values.put(MySQLiteGUESTS.COLUMN_CLICK, 1); 
     } 
    } 
    String newString = MySQLiteGUESTS.COLUMN_NAME + " = " + name; 
    database.update(MySQLiteHelper.TABLE_NAME, values, newString, null); 

    } 
+0

何 'comment.getClick()'メソッドの戻り? –

+2

!=名前が間違っています。 .equalsを使って文字列を比較していないのはなぜですか? –

+0

David Rawsonは絶対に正しいです。文字列を比較する場合は、equals()でそれを行う必要があります。例: 'if(!comment.getName()。toString()。equals(name))' – Opiatefuchs

答えて

0

if (comment.getName().toString() != name)

の代わりにこの 使用この: if (comment.getName().toString().equals(name)) { }