RecyclerView点击跳转详情页图片不显示,Activity传递Firebase图片字符串问题
Got it, let's get that image showing up in your detail page! You already nailed down the root cause—you're trying to retrieve a String-based image URL with getIntExtra(), and on top of that, setImageResource() is only meant for local drawable resources, not remote URLs from Firebase. Here's how to fix it step by step:
Step 1: Correctly Retrieve the Image URL in the Detail Activity
First, replace the incorrect getIntExtra() call with getStringExtra() to grab the actual image URL string from your intent:
// Remove this wrong line: // imageView.setImageResource ( getIntent ().getIntExtra ( "image", Integer.parseInt ( "00" ) )); // Replace with this to get the String URL: String imageUrl = getIntent().getStringExtra("image");
Step 2: Load the Remote Firebase Image with an Image Loading Library
Since your image is stored in Firebase (as a remote URL), setImageResource() won't work—it can't handle network requests. The easiest and most reliable solution is to use a dedicated image loading library like Glide (the go-to choice for Android developers).
Add Glide Dependency
First, add Glide to your app-level build.gradle file, then sync your project:
dependencies { implementation 'com.github.bumptech.glide:glide:4.16.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0' }
Use Glide to Load the Image
Update your detail activity code to load the Firebase image URL into your ImageView:
Glide.with(this) .load(imageUrl) // Pass the Firebase image URL here .placeholder(R.drawable.placeholder_image) // Optional: Show a placeholder while loading .error(R.drawable.error_image) // Optional: Show an error image if loading fails .into(imageView);
Step 3: Verify Firebase Access
Double-check two key things to ensure the image loads properly:
- The
Imagefield in your Firebase database contains a valid, publicly accessible URL (if it's from Firebase Storage, make sure your storage rules allow read access for the user). - The
clickedDataItem.getImage()call in your RecyclerView ViewHolder is correctly fetching this URL (your existing code here looks solid!).
Alternative: Without Third-Party Libraries (Not Recommended)
If you really don't want to use a library, you'd have to write a background thread to download the image, convert it to a Bitmap, and set it to the ImageView. But this is error-prone—you'll have to handle caching, network errors, screen rotation, etc.—so using Glide or Picasso is strongly advised.
内容的提问来源于stack exchange,提问作者Nesrine

