I have been trying from long time to solve the problem. I'm beginner in android studio programming language "Java". I'm trying to load images from phone storage into my application but the problem is when I click on ImageView it shows the image path which I set it already onClick, but it not showing the image in image view what should I do. Do you have any source code of gallery application. Below I shared my code. Please help me if you have proper knowledge I'll be thankful. And sorry for my English.
' public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.MyViewHolder>{
private Context mContext;
private List<String> images;
private PhotoListener photoListener;
public GalleryAdapter(Context mContext, List<String> images, PhotoListener photoListener) {
this.mContext = mContext;
this.images = images;
this.photoListener = photoListener;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new MyViewHolder(
LayoutInflater.from(mContext).inflate(R.layout.gallery_item , parent , false)
);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
String image = images.get(position);
Glide.with(mContext).load(image).into(holder.imageView);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
photoListener.onPhotoClick(image);
}
});
}
@Override
public int getItemCount() {
return images.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.ImageView);
}
}
public interface PhotoListener{
void onPhotoClick(String path);
}
}
public class ImageGallery { public static ArrayList listOfImages(Context context){
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String [] projection = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
String orderBy = MediaStore.Images.Media.DATE_MODIFIED;
Cursor cursor = context.getContentResolver().query(uri , projection, null , null , orderBy + " DESC");
String absolutePathOfImage;
ArrayList<String> ImagesList = new ArrayList<>();
int columnIndexData = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
while (cursor.moveToNext()){
absolutePathOfImage = cursor.getString(columnIndexData);
ImagesList.add(absolutePathOfImage);
}
return ImagesList;
}'