Video Thumbnail Arrayadopter Is Slow On Scroll
Solution 1:
The listview is lagging because you are creating new Thumbnails in getView() every time. There is just no caching or re-use. As the use scrolls up/down , getView() is called and time consuming process of creating thumbnails happen, hence the lag. You will also run Out of Memory
soon.
Create and keep an Array of Bitmaps, with the same length as the number of elements in the datasource and store your thumbnails in the array. Take out the bitmap from the array for that particular position inside getView()
. This should considerably increase the performance.
EDIT I have added a Hasmap of bitmaps to demonstrate the re-use.
publicMyAdapter(Activity context, String[] names) {
super(context, R.layout.rowlayout, names);
this.context = context;
this.names = names;
filePath = Environment.getExternalStorageDirectory() + dirNameSlash;
formatter = newSimpleDateFormat(dateFormat);
cacheBitmap = newHashMap<String, Bitmap>(names.length);
initCacheBitmap();
}
privatevoidinitCacheBitmap() {
for(Stringstring:names)
cacheBitmap.put(string, ThumbnailUtils.createVideoThumbnail(filePath+string, Thumbnails.MICRO_KIND));
}
@OverridepublicViewgetView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.rowlayout, null);
ViewHolder viewHolder = newViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.label);
viewHolder.image = (ImageView) rowView.findViewById(R.id.icon);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
// Video file nameString s = names[position];
holder.text.setText(s);
holder.image.setImageBitmap(cacheBitmap.get(s));
return rowView;
}}
Solution 2:
Since you are creating Thumnail for video inside getView() it slow down your scrolling.
So you have to save your bitmap in Arrarys and list it i scroll.. Try this Sample for this will really helps you for fast scrolling. This Sample includes images , you have to change for Video in Media Content Providers. Fast Scroll Sample
Post a Comment for "Video Thumbnail Arrayadopter Is Slow On Scroll"