更新所选用户ID IN ANDROID的数据库中的列

时间:2013-06-03 09:03:31

标签: android sql arraylist

有人可以帮我解决这个问题吗?我有一个带有复选框的列表视图,每次用户勾选复选框时,所有选定的用户ID都被插入到一个arraylist中。然后,如果单击按钮Export,则数据库中的所有“Mark”列都应从“Not send”更新为“sent”。我知道通过这段代码,数据库将会更新:

public void updateEmailmark(String consumerId) 
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(Constants.CONSUMER_EMAILMARK, "Sent");
    db.update(Constants.DATABASE_TABLE_CONSUMER, contentValues, Constants.CONSUMER_ID + "=?",new String[]{consumerId});
    db.close();
}

但我的问题是,当用户选择了许多要导出的UserID时,我不知道如何更新该列。我只知道我需要使用for循环,但我不知道如何。感谢任何能帮助我的人。这是我的其他代码。

btn_Export.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v){
            arraylistSelectedConsumerIds = simpleAdapterConsumerData.getArrayListConsumerId();
            arraylistSelectedConsumer = simpleAdapterConsumerData.getArrayListConsumer();

            if (!arraylistSelectedConsumerIds.toString().equals("[]") && !arraylistSelectedConsumer.toString().equals("[]"))
            {
                boolean hasSDCard = false;
                boolean sdCardIsWriteable = true;
                String sdCardState = Environment.getExternalStorageState();
                if (Environment.MEDIA_MOUNTED.equals(sdCardState))
                    hasSDCard = true;
                else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(sdCardState))
                    sdCardIsWriteable = true;

                if (hasSDCard == true && sdCardIsWriteable == true){
                    new AsyncCreateBackup().execute();

                    String date = String.valueOf(calendar.get(Calendar.MONTH)+1)+"-"+String.valueOf(calendar.get(Calendar.DATE))+"-"+String.valueOf(calendar.get(Calendar.YEAR));

                    int fileCounter = 1;
                    File sdcard = Environment.getExternalStorageDirectory();
                    File dir    =   new File (sdcard.getAbsolutePath() + "/CompanyCares/export/");
                    if (dir.exists()){
                        File[]dirs = dir.listFiles();

                         try{
                             for(File fileFolder: dirs){
                                if(fileFolder.isDirectory() && fileFolder.getName().contains("export_"+date)){
                                    fileCounter++;
                                }
                             }
                         } catch (Exception e){
                             e.printStackTrace();
                         }
                    }

                    consumerData = new StringBuilder();
                    File personFile;
                    time = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))+String.valueOf(calendar.get(Calendar.MINUTE))+String.valueOf(calendar.get(Calendar.SECOND));
                    personFile = createCSV("Person_Table_"+date+"_"+time, Constants.COLUMN_STRING_PERSON_TABLE, getConsumersDetails(arraylistSelectedConsumerIds), fileCounter, false);

                    createEmailWithAttachments(personFile);

                    arrayListExportedConsumerId.addAll(arraylistSelectedConsumerIds);
                    arrayListExportedConsumer.addAll(arraylistSelectedConsumer);

                    exportedConsumerId = new HashSet<String>();
                    exportedConsumer = new HashSet<String>();
                    exportedConsumerId.addAll(arrayListExportedConsumerId);
                    exportedConsumer.addAll(arrayListExportedConsumer);

                    sharedPreferencesEditor.putStringSet(Constants.SHARED_PREFERENCES_EXPORTED_CONSUMER_ID, exportedConsumerId);
                    sharedPreferencesEditor.putStringSet(Constants.SHARED_PREFERENCES_EXPORTED_CONSUMER, exportedConsumer);
                    sharedPreferencesEditor.commit();
                }else{
                    Toast.makeText(AdminActivity.this, getString(R.string.error_sdcard), Toast.LENGTH_SHORT).show();
                }
            }else{
                Toast.makeText(AdminActivity.this, getString(R.string.error_select), Toast.LENGTH_LONG).show();
            }
        }
    });

0 个答案:

没有答案