【问题标题】:Dynamic add items to listview using arrayadapter使用 arrayadapter 将项目动态添加到列表视图
【发布时间】:2015-07-12 10:25:21
【问题描述】:

//在列表视图中显示 Youtube 视频:我正在制作一个 android 应用程序以开始使用 youtube api 即时搜索编辑文本,然后当操作完成时,它应该在我的列表视图中显示视频.. 问题我有它只在列表视图中显示 5 个视频,我希望它是动态的,所以当我向下滚动时它会显示 5 个其他视频等等,我该怎么做?

private void updateVideosFound() {
     ArrayAdapter<VideoItem> adapter = new ArrayAdapter<VideoItem>(getApplicationContext(), R.layout.video_item, searchResults) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {


            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.video_item, parent, false);
            }
            ImageView thumbnail = (ImageView) convertView.findViewById(R.id.video_thumbnail);
            TextView title = (TextView) convertView.findViewById(R.id.video_title);
            TextView description = (TextView) convertView.findViewById(R.id.video_description);

            VideoItem searchResult = searchResults.get(position);

            Picasso.with(getApplicationContext()).load(searchResult.getThumbnailURL()).into(thumbnail);
            title.setText(searchResult.getTitle());
            description.setText(searchResult.getDescription());
            return convertView;
        }
    };

    videosFound.setAdapter(adapter);

    videosFound.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }



        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {


        }
    });
}

【问题讨论】:

    标签: android git listview video youtube


    【解决方案1】:

    您需要在列表视图上设置滚动侦听器。可能这个链接可以帮助你。

    Detect Scroll Up & Scroll down in ListView

    您需要确定您是否在视图的最后一个单元格上。然后你需要对接下来的 5 - 10 条记录再次运行查询并将其添加到列表视图中

    【讨论】:

    • 怎么样?你能帮我吗因为我是android新手:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多