【问题标题】:YouTube's response array, sorting programmaticallyYouTube 的响应数组,以编程方式排序
【发布时间】:2016-10-28 17:01:50
【问题描述】:

我正在创建一个可以在其中进行 youtube 搜索的应用。它目前工作正常,我只是想通过按标题名称对它们进行排序来显示更好的结果。

我得到一个包含 50 个项目的 VideoListResponse

VideoListResponse videoListResponse = null;
    try {
        videoListResponse = mYouTubeDataApi.videos()
                .list(YOUTUBE_VIDEOS_PART)
                .setFields(YOUTUBE_VIDEOS_FIELDS)
                .setKey(ApiKey.YOUTUBE_API_KEY)
                .setId(TextUtils.join(",", videoIds)).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }

我想按标题对它们进行排序。让我显示项目列表的图像:

【问题讨论】:

    标签: java android youtube youtube-api


    【解决方案1】:

    嗯,YouTube API 已经支持按标题排序结果。你不需要做任何事情......

    https://developers.google.com/youtube/v3/docs/search/list#parameters

    【讨论】:

      【解决方案2】:

      您可以在其中检索List 并对其进行排序:

      List<Video> items = videoListResponse.getItems();
      items.sort(Comparator.comparing(e -> e.getSnippet().getTitle()));
      

      【讨论】:

      • 感谢您的回答,我最终这样做了:List&lt;Video&gt; items = videoListResponse.getItems(); Collections.sort(items, new Comparator&lt;Video&gt;() { @Override public int compare(Video video, Video t1) { return video.getSnippet().getTitle().compareToIgnoreCase(t1.getSnippet().getTitle()); } }); return new Pair(searchResponse.getNextPageToken(), items);
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 2011-02-02
      • 2017-02-22
      • 1970-01-01
      • 2020-05-03
      • 2012-12-01
      相关资源
      最近更新 更多