listview-SQLite更新错误的行

时间:2016-12-19 10:59:39

标签: android

当我更新所选行时,它会更新错误的行,例如,如果我选择第二行,它将更新第一行。

这是我在db controller

中的代码
#!/usr/bin/env perl

use strict;
use warnings;

open ( my $has_seq, '>', 'SEQ' ) or die $!;
open ( my $no_seq, '>', 'NO_SEQ' ) or die $!;
my $seq_count = 0;
my $no_seq_count = 0;

local $/ = 'END'; 

#iterate stdin or files specified on command line, just like sed/grep
while ( <> ) {
    #check if this chunk contains the word 'SEQ'.
    #regex match, so it'll match this text anywhere. 
    #maybe need to tighen up to ^SEQ= or similar? 
    if ( m/SEQ/ ) { 
        #choose output filehandle
        $seq_count++;
        select $has_seq;
    }
    else { 
       $no_seq_count++;
       select $no_seq;
    }
    #print current block to selected filehandle. 
    print;
}

select \*STDOUT; 
print "SEQ: $seq_count\n"; 
print "No SEQ: $no_seq_count\n";

这是我的按钮onclick更新列表视图:

Public boolean updateContact (String id, String category, String code, String description, String unit, String quantity) {

    SQLiteDatabase database = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(FeedReaderContract.FeedEntry.Col_2 , category);
    values.put(FeedReaderContract.FeedEntry.Col_3 , code);
    values.put(FeedReaderContract.FeedEntry.Col_4 , description);
    values.put(FeedReaderContract.FeedEntry.Col_5 , unit);
    values.put(FeedReaderContract.FeedEntry.Col_6 , quantity);
    // updating row
     database.update(TABLE_NAME  ,values , FeedReaderContract.FeedEntry.Col_1 + " = ?" , new String[]{id} );
    return true;

}
public ArrayList<HashMap<String, String>> getAllProducts() {
    ArrayList<HashMap<String, String>> proList;
    proList = new ArrayList<HashMap<String, String>>();
    String selectQuery = "SELECT  * FROM Countsheet";
    SQLiteDatabase database = this.getWritableDatabase();
    Cursor cursor = database.rawQuery(selectQuery, null);
    if (cursor != null && cursor.moveToFirst()) {
        do {

            HashMap<String, String> map = new HashMap<String, String>();

            map.put("Category", cursor.getString(1));
            map.put("Code", cursor.getString(2));
            map.put("Description", cursor.getString(3));
            map.put("Unit", cursor.getString(4));
            map.put("Quantity", cursor.getString(5));
            proList.add(map);

        } while (cursor.moveToNext());
        cursor.close();

    }

    return proList;

}

2 个答案:

答案 0 :(得分:0)

我认为你错过了'passid'。

在从数据库中提取然后检索时,在您的HashMap中放入'passid'。

答案 1 :(得分:0)

嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿嘿I I I,,,,,,I I I I I I I I I I I W W W V V V V V V V V V V V V V V V V V V V V V V AND AND AND AND AND AND AND AND AND

//这是我的代码

intent.putExtra(ID_EXTRA1,String.valueOf(id + 1));                 startActivity(意向);