为什么 Glide 只处理原始字符串网址数据?(安卓工作室)



我可以成功地使用带有 glide 的字符串 url 来获取我想要的图像:

glideVariable!!.loadImageUrl("https://firebasestorage.googleapis.com/v0/b/healthandchocolate-46f3d.appspot.com/o/cookies%2FcookiesImg1.jpg?alt=media&token=63721d7d-207e-441c-9387-14dced13d3c8")

但是当我尝试使用存储在变量中的相同 url 时,图像不会加载:

glideVariable!!.loadImageUrl(recipeArray[1].recipeImage.toString())

我已经对recipeArray[1].recipeImage.toString()进行了Log.d,它确实包含与使用原始字符串数据在我的第一个示例中工作的相同 url。

我使用转义命令将变量封装在引号中,如下所示:

glideVariable!!.loadImageUrl("${recipeArray[1].recipeImage.toString()}")

但它仍然不起作用。我也试图把它塑造成URLURI,但仍然没有。有什么想法吗?滑翔只能使用原始字符串数据吗?

更新我注意到recipeArray[1].recipeImage同时包含keyvalue。也许这就是问题所在。它不会直接访问 url 字符串。如何确保只使用字符串值?它看起来像这样:

DataSnapshot { key = recipeImageFirebase, value = https://firebasestorage.googleapis.com/v0/b/healthandchocolate-46f3d.appspot.com/o/cookies%2FcookiesImg1.jpg?alt=media&token=63721d7d-207e-441c-9387-14dced13d3c8 }

好的,现在明白了。recipeArray[1].recipeImage.toString()是包含键和字符串的数据快照。我回到存储变量时:

val image = item.child("recipeImageFirebase")
tempRecipe.recipeImage = image.toString()

并将最后一部分更改为

tempRecipe.recipeImage = image.value.toString()

现在它只包含字符串值,而不是键"recipeImageFirebase"!

最新更新