android 日常(十九)

2017-01-03  本文已影响35人  ncd
List<String> threadIdList = new ArrayList<String>();
        List<String> parameters = new ArrayList<String>();
        Uri uri = MessageSQL.CONTENT_URI;
        String[] projection = {new String("distinct "+MessageSQL.thread_id)};
        String selection = MessageSQL.boxid+"= ?";
        String[] selectionArgs1 = {String.valueOf(MessageSQL.MESSAGE_TYPE_FAILED)};
        Cursor cursor = getContext().getContentResolver().query(uri, projection, selection, selectionArgs1, null);
        
        
        while(cursor.moveToNext()){
            int threadId = cursor.getInt(0);
            threadIdList.add(String.valueOf(threadId));
            parameters.add("?");
        }
        cursor.close();
        
        
        Uri threadUri = QThread.THREAD_URI;
        ContentResolver mContentResolver = getContext().getContentResolver();
        ContentValues values = new ContentValues();
        values.put(QThread.error, 0);
        String where = QThread._ID+" not in ("+TextUtils.join(",", parameters)+")";
        String[] selectionArgs2= threadIdList.toArray(new String[threadIdList.size()]);
        mContentResolver.update(threadUri, values, where, selectionArgs2);

此处的解决方法是先获取参数,根据参数的个数设置“?”,
String where = QThread._ID+" not in ("+TextUtils.join(",", parameters)+")";,然后在update方法中将
参数数组selectionArgs传入,效果相当于sql中的
select <YOUR SELECTIONS> from <YOUR TABLE NAME> where *** in/not in (arg1,arg2,....)

上一篇下一篇

猜你喜欢

热点阅读