Reputation: 160
I was trying to list all the images and videos in a folder but setting it in recyclerview nor gridview gives a good result. it stucks in the scroll. Please suggest a way how to display all the files in a better way.
This is how i fetch files,
listFile = AllUtils.getFiles(fetchPath, mContext);
displaying part in recyclerview
public void onBindViewHolder(@NonNull DetailViewHolder holder, final int position) {
if (listFile.get(position).toString().contains("mp4")) {
Bitmap myBitmap = ThumbnailUtils.createVideoThumbnail(listFile.get(position).toString(), MediaStore.Video.Thumbnails.MINI_KIND);
holder.ivIcon.setImageBitmap(myBitmap);
holder.ivPlay.setVisibility(View.VISIBLE);
}
}
Upvotes: 2
Views: 1142
Reputation: 1270
There are various free open-source libraries are available for android on GitHub for working with images and videos.
I think using BitMap
for displaying images is not a good idea instead of BitMap
you should use Glide
library for displaying images and use fenster
for videos.
Import Glide in your project
repositories {
mavenCentral()
google()
}
dependencies {
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
Display Image like this:
GlideApp
.with(myFragment)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.into(myImageView);
You can also upload image using url
GlideApp.with(this).load("http://........").into(imageView);
read more about glide and fenster.
Upvotes: 2
Reputation: 1354
I had the same problem when I was showing images from list in recylerview. Since recylerview caches and recyles the views inside itself getting position in recylerview may fail for your index in listfile. By increasing the cache size of your recylerview to the number of items in listfile makes sures that the position in recylerview is the exact position in your listfile. Add this line of code to your recylerview before setting adapter.
// Let's say you have 30 items in your listfile
// Or if you cannot make sure the number of items give a bigger number
recyclerView.setItemViewCacheSize(30);
Hope it helps.
Upvotes: 1