The image is not showing up, the context is passed from the activity with the recycleView on the Adapter Constructor.
The error code is :
com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: gs://my-data-7pt42.appspot.com/CompanyImages/aMBvmcvfh6RCwGn3n0WYCYY7Nxo1/logo.jpg
What I'm trying is :
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
StorageReference reference = firebaseStorage.getReference().child("CompanyImages/"+idParser.get(position)+"/logo.jpg");
holder.companyName.setText(allCompanies.get(position));
Glide.with(context)
.load(reference)
.into(holder.imageRowCompany);
}
I also tried replacing context with holder.imageRowCompany.getContext()
Any help would be appreciated! Thanks!
When you will log the value of reference , it will not return an Image URL of logo.png,instead you will get the location of your file on google cloud.
You need to get image url of logo.png.
Here you can check how to get the download url of any file from firebase. Link
Related
i have been trying to display images in my recyclerview, i had seen a lot of tutorials, but i can't.
this is my onBindViewholder in my adapter class
#Override
public void onBindViewHolder(#NonNull final cowviewHolder holder, int position) {
final Cow vacaslist = vacas.get(position);
holder.textViewinterno.setText(vacaslist.interno);
holder.textViewsiniiga.setText(vacaslist.siniiga);
Picasso.get().load(vacaslist.ulr)
.resize(80,80).centerCrop().error(R.drawable.ic_imageinf).into(holder.imageviewrec);
This is my database in firebase, im taking the images from storage
Thanks.. If need more info let me know
I think the problem is your ulr variable name because on firebase it is url so, if you are instantiating your Cow object using following syntax:
ref.child("Vacas").child("$id").getValue(Cow.class);
Then ulr will be null.
I could get it right with Realtime Database, but I went over to Cloud FireStore and now I'm running into some problems. I want to display an image that is in Firestore via a download URL from Firestore. I'm using the FirestoreRecyclerAdapter, I want to populate an imageView in a RecyclerView.
I tried to do it the same way it worked in Realtime Database, but I get an error, but this time I get an error telling me NumberFormatException: For input string:
#Override
protected void onBindViewHolder(#NonNull NoteHolder holder, int p,
#NonNull promo_one_data promo_one) {
holder.produk_product.setText(promo_one.getProduct());
holder.produk_discription.setText(promo_one.getDiscription());
holder.produk_discription_two.setText(promo_one.getDiscription_two());
holder.produk_size.setText(promo_one.getSize());
holder.produk_product_two.setText(promo_one.getProduct_two());
holder.produk_price.setText(promo_one.getPrice());
holder.produk_department.setText(promo_one.getDepartment());
if ("1".equals(holder.produk_department.getText().toString())) {
holder.itemView.setBackgroundColor(Color.parseColor("#FFCDD2"));
} else if ("2".equals(holder.produk_department.getText().toString())) {
holder.itemView.setBackgroundColor(Color.parseColor("#FFA6AF"));
} else {
holder.itemView.setBackgroundColor(Color.WHITE);
}
holder.produk_image.setImageResource(Integer.parseInt(promo_one.getImage()));
Picasso.get().load(promo_one.getImage()).into(holder.produk_image);
}
#NonNull
#Override
public NoteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_promo, parent, false);
return new NoteHolder(v);
}
How can I display an image in a recyclerView from Cloud Firestore. It shows me "java.lang.NumberFormatException: For input string:...(the URL here), which I could gather means the string is to long to convert into a int to fill the imageView. How do I do this, or is there a way around? Or even how do I shorten the URL, or maybe is there a way to do it and not use Picasso?
Your problem is this line :
holder.produk_image.setImageResource(Integer.parseInt(promo_one.getImage()));
you should not be trying to parse the URL of the image to an integer here, the next line using Picasso:
Picasso.get().load(promo_one.getImage()).into(holder.produk_image);
should handle the image loading for you.
I'm using firebase database(firebaseUI) for loading text in cardviews recyclerView, but my images are stored in firebase storage. How can I populate my cardviews with a different image for each cardview using Glide?
-Should I only use FirebaseUI database in my code(with Glide) with 'image' as key and the Firebase storage url as value, ie { image:FirebaseStorageURLOfOneImage }? While manually uploading image to firebase storage.
-Or is there a way to use both FirebaseUI database & storage in my code(with Glide), and still load one different image per cardview?
I only use FirebaseUI database in my code(with Glide) with 'image' as key and the Firebase storage url as value, ie { image:FirebaseStorageURLOfOneImage }
public void onBindViewHolder(#NonNull PropertyViewHolder holder,
final int position, #NonNull final Property model) {
holder.setPropertyImage(model.getPropertyImage());
}
//...code skipped...
public void setPropertyImage(String propertyImage){
ImageView imageView = mView.findViewById(R.id.post_propertyImage);
// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(getContext())
.load(propertyImage)
.fitCenter()
.into(imageView);
}
I can load image path to imageView using Glide in this code:
GlideApp.with(context)
.load(imagePath)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.transition(withCrossFade())
.into(imageView);
I do not want to load previously registered same path or bitmap from imageView.
==============UPDATE=================
I find this solution (thanks ADM):
Glide automatically performs setTag() function and when I call imageView.getTag() function, result is deriving SingleRequest which has loaded data (imagePath or bitmap).
But I can't access singleRequest model field, it is a private. How can I take singleRequest model field? Please help me.
As discussed you should tag e url with view.setTag().
Here setTag(Object object) takes object as argument . Whenever we call getTag() we need to cast it. below is the example.
view.setTag("htttp://www.imgur.3877383.jpg");
String url =(String)view.getTag();
if(url!=null){
// Use the url
}
Cause Argument is an Object so you can also add class object as tag.
view.setTag(myPozo);
MyPozo myPozo =(MyPozo)view.getTag();
if(myPozo!=null){
// Use the pozo
}
Also i am not aware with the use of this . But if you are working on List (ListView or RecyclerView etc) then you can directly access the dataset attached with the view by position.
you can't take "image path" from imageView by using Glide or any other libraries, one can set image bitmap or background in the imageView so you can get bitmap back from imageview if you want but you cannot get imagepath back from imageview.
if you wants to remember image path with you are going to apply as a bitmap in imageview you can do it via add the image path to arraylist and use it when needed
Try this code :
Glide.with(this).load(Uri.parse(resultUri)).asBitmap().into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
if (resource != null) {
myTouchView1.setImageBitmap(resource);
}
}
});
You should read:
Guide Documentation
The imagepath will be something like:
String asseturl = "file:///android_asset/demo1.jpg";
Glide.with(context).load(asserturl)....
I am trying to load images in a recycler View using Picasso using the code
Picasso.with(context).load(songs.CoverArtAlbumPath.get(position)).into(holder.primaryImageView, new Callback() {
#Override
public void onSuccess() {
Log.v("abc","suc");
}
#Override
public void onError() {
Log.v("abc","err");
}
});
And it always ends up in onError() method. I tried to load the images using the traditional way by using BitmapFactory.decodeFile and other methods and then it was working fine.
The songs.CoverArtAlbumPath.get(position) contain strings like as "/storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1456505346363"
I also tried to load an image from the drawable folder by just changing the .load() parameters in the Picasso code and it got loaded. That means no error in the context and ImageView I am using here.
The string which I am passing in the .load() method is the string path for the Cover Art of the Album from the MediaStore.
The ImageView used here is the View in the following xml code
<ImageView
android:gravity="left"
android:id="#+id/grid_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
Please Help to tell that what is wrong and what should I do to make it work.
Thanks in advance.
you can try this:
for showing image with storage path:
String path ="/storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1456505346363.png";
Picasso.with(mContext).load("file://" + path)
//.transform(new util.CircleTransform())// optional
//.placeholder(R.drawable.default1) // optional
.error(R.drawable.default1) // optional
.into(holder.primaryImageView);
for showing image from url:
String url ="http://www.domain_name.com/image.png";
Picasso.with(mContext)
.load(url)
//.placeholder(R.drawable.default1) // optional
.error(R.drawable.default1) // optional
//.transform(new CircleTransform())// optional
.into(holder.primaryImageView);
You are doing it wrong try this
String path ="/storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1456505346363.png";
Picasso.with(context).load(new File(path)).into(holder.primaryImageView);
For more Information go to http://square.github.io/picasso/