如何从同一列的多个值中获取行

时间:2015-12-10 22:05:34

标签: android android-sqlite

根据此声明,我会在列MediaStore.Audio.Albums._ID = 16

中找到一行
    String[] stringArray = {"16"};
    final Cursor mCursor = getContentResolver().query(
            MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, // Uri
            new String[]{                                 // String[] projection (columns)
                    MediaStore.Audio.Albums.ALBUM_ART,
                    MediaStore.Audio.Albums.ARTIST,
                    MediaStore.Audio.Albums.ARTIST,
                    MediaStore.Audio.Albums.NUMBER_OF_SONGS,
                    MediaStore.Audio.Albums.ALBUM_KEY
            },
            MediaStore.Audio.Albums._ID + "=?",           // String selection
            stringArray,                                  // String[] selectionArgs
            null,                                         // sortOrder
            null                                          // CancellationSignal
    );

现在我怎样才能获得同一列有多个值的多行,例如MediaStore.Audio.Albums._ID = 16,25,24,30,...etc

这样的东西?

String[] stringArray = {"16","25","24","30","14","31","28","23","17","16","13"}; 
final Cursor mCursor = getContentResolver().query(
        MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, // Uri
        new String[]{                                 // String[] projection (columns)
                MediaStore.Audio.Albums.ALBUM_ART,
                MediaStore.Audio.Albums.ARTIST,
                MediaStore.Audio.Albums.ARTIST,
                MediaStore.Audio.Albums.NUMBER_OF_SONGS,
                MediaStore.Audio.Albums.ALBUM_KEY
        },
        MediaStore.Audio.Albums._ID + "=?",           // String selection
        stringArray,                                  // String[] selectionArgs
        null,                                         // sortOrder
        null                                          // CancellationSignal
);

2 个答案:

答案 0 :(得分:0)

您的mSelectionClause MediaStore.Audio.Albums._ID + "=?",不正确。

Documentation说你需要一个“?”对于每个被替换的论点。

答案 1 :(得分:0)

使用运算符IN: http://www.w3schools.com/sql/sql_in.asp

tableB

希望这对你有所帮助。