0

//Displaying Youtube videos in a listview : i'm making an android application to get started with youtube api im doing the search of an edit text then when action done its should display the videos in my list view .. the problem i have that it only displays 5 videos in the list view and i want that to be dynamic so when i scroll down it displays 5 another videos and so on how can i do this ?

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) {


        }
    });
}

1 Answers1

0

You need to set on scroll listener on listview. May be this link can help you.

Detect Scroll Up & Scroll down in ListView

You need to find whether you are on the last cell of the view. Then you need to run the query again for next 5 - 10 records and add it to listview

Community
  • 1
  • 1
Priya Singhal
  • 1,261
  • 11
  • 16