1

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

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();
            }
        }
    });
4

0 回答 0