java - Scrolling is not smooth, its too slow. I've retrieved videos form SD card and showing them listview -


please tell me how can smooth scrolling. when try scroll down takes lot of time load videos thumbnails. please check code , give me easy solution. many thanks.

i have tried lot of ways not working. don't know how deal issue. hope experts me complete project.

public class videoadapter extends baseadapter {     private context vcontext;      public videoadapter(context c) {         vcontext = c;     }      public int getcount() {         return count;     }          public object getitem(int position) {             return position;         }          public long getitemid(int position) {             return position;         }          public view getview(int position, view convertview, viewgroup parent) {               system.gc();                 viewholder holder;                 string id = null;                 convertview = null;              if (convertview == null) {                 try {                 convertview = layoutinflater.from(vcontext).inflate(                         r.layout.itemlist, parent, false);                 }                 catch (exception e)                 {                     toast.maketext(getcontext(),"permission granted" + e, toast.length_short).show();                 }                      holder = new viewholder();                 try {                     holder.txttitle = (textview) convertview                             .findviewbyid(r.id.txttitle);                     holder.txtsize = (textview) convertview                             .findviewbyid(r.id.txtsize);                     holder.thumbimage = (imageview) convertview                             .findviewbyid(r.id.imgicon);                 }                 catch (exception e)             {                 toast.maketext(getcontext(),"permission granted" + e, toast.length_short).show();             } try {     video_column_index = songcursor             .getcolumnindexorthrow(mediastore.video.media.display_name);     songcursor.movetoposition(position);     id = songcursor.getstring(video_column_index);     video_column_index = songcursor             .getcolumnindexorthrow(mediastore.video.media.size);     songcursor.movetoposition(position); } catch (exception e) {     toast.maketext(getcontext(),"permission granted" + e, toast.length_short).show();  }                 // id += " size(kb):" +                 // videocursor.getstring(video_column_index);                 holder.txttitle.settext(id);                 holder.txtsize.settext(" size(kb):"                         + songcursor.getstring(video_column_index)); try {     string[] proj = {mediastore.video.media._id,             mediastore.video.media.display_name,             mediastore.video.media.data};      @suppresswarnings("deprecation")     cursor cursor = getactivity().getcontentresolver().query(             mediastore.video.media.external_content_uri, proj,             mediastore.video.media.display_name + "=?",             new string[]{id}, null);     cursor.movetofirst();  } catch (exception e) {     toast.maketext(getcontext(),"no permission granted" + e, toast.length_short).show();  }      long ids = songcursor.getlong(songcursor             .getcolumnindex(mediastore.video.media._id));      contentresolver crthumb = getactivity().getcontentresolver();     bitmapfactory.options options = new bitmapfactory.options();     options.insamplesize = 1;     bitmap curthumb = mediastore.video.thumbnails.getthumbnail(crthumb, ids, mediastore.video.thumbnails.micro_kind, options);            ///     if (holder.thumbimage !=null) {                     holder.thumbimage.setimagebitmap(curthumb);               //  }           //      else {           //          drawable = getcontext().getresources().getdrawable(r.drawable.index);            ///         holder.thumbimage.setimagedrawable(a);                //  }      curthumb = null; }               return convertview;           }          }      static class viewholder {          textview txttitle;         textview txtsize;         imageview thumbimage;     } 

don't code in getview() method, because runs everytime scroll list, cause of slow scrolling, don't need fetch bitmaps of videos may generate outofmemoryexception, fetch paths of videos in fragment or activity pass list of paths constructor of adapter, use glide library show thumbnail of video using path: put line in app gradle

compile 'com.github.bumptech.glide:glide:4.1.1' 

then write code show thumbnail of video:

glide.with(vcontext).load(paths[position]).into(holder.thumbimage); 

you can path cursor:

protected string[] getpaths() {     cursor cursor = getactivity().getcontentresolver()             .query(mediastore.images.media.external_content_uri, projection,                     null, null, null);     if (cursor == null)         return null;      string[] paths = new string[cursor.getcount()];     file file;      int = 0;     if (cursor.movetofirst()) {         {             string path = cursor.getstring(cursor.getcolumnindex(mediastore.video.media.data));                 /*                 may happen image file paths still present in cache,                 though image file not exist. these last long media                 scanner not run again. avoid such image file paths, check                 if image file exists.                  */             file = new file(path);              if (file.exists()) {                 paths[i] = path;                 i++;             }          } while (cursor.movetonext());     }     cursor.close();     return paths; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -