我了解的类型:

public static CursorLoader getGenres(Context context) {
    Uri uri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
    String[] columns = { MediaStore.Audio.Genres._ID,
            MediaStore.Audio.Genres.NAME };
    String orderBy = MediaStore.Audio.Genres.NAME;

    return new CursorLoader(context, uri, columns, null, null, orderBy);
}

但是我需要每种流派的歌曲数量。我可以针对每种类型执行此操作:
private int getNumberSongsOfGenre(long genreID) {
    Uri uri = MediaStore.Audio.Genres.Members.getContentUri(VOLUMENAME,
            genreID);
    Cursor c = resolver.query(uri, null, null, null, null);

    if (c == null || c.getCount() == 0)
        return -1;

    int num = c.getCount();
    c.close();

    return num;
}

...但是我需要在同一查询中执行此操作并返回CursorLoader。任何的想法?

最佳答案

我也在寻找相同的东西,但仍然没有任何适当的解决方案。但是,如果您只关心要显示的歌曲数,则可以执行以下我的回答。

@Override
    public void bindView(View v, Context context, Cursor c) {
        int index;
        long genreId;
        Uri uri;
        ViewHolder holder  =   (ViewHolder)    v.getTag();

         holder.titleName.setText(c.getString(c.getColumnIndex(MediaStore.Audio.Genres.NAME)));
         //===========================

         index = c.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);
         //Log.i("Tag-Genre name", c.getString(index));

         index = c.getColumnIndexOrThrow(MediaStore.Audio.Genres._ID);
         //genreId=Long.parseLong(c.getString(index));
         genreId  = c.getLong(c.getColumnIndexOrThrow(MediaStore.Audio.Genres._ID));
         uri = MediaStore.Audio.Genres.Members.getContentUri("external", genreId);
         String[] proj2={MediaStore.Audio.Media.DISPLAY_NAME};
         Cursor tempcursor = context.getContentResolver().query(uri, proj2, null,null,null);
         //tempcursor.moveToFirst();
         //Log.i("Tag-Number of songs for this genre", tempcursor.getCount()+"");
         holder.artistName.setText(""+tempcursor.getCount()+" Songs");

    }

如果您只关心其中的歌曲数,希望您能得到答案。

关于android - 如何在Android的一次查询中获取流派和每种流派的歌曲数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14265925/

10-09 04:52