【发布时间】:2018-04-19 23:27:40
【问题描述】:
如果我事先将 URL 存储为字符串,我可以使用它的 URL 在我的图像按钮中下载图像,但是当我尝试使用存储引用在我的图像按钮中加载相同的图像时没有任何反应。我确实将存储引用转换为字符串并将其显示在文本按钮上,以确保我拥有正确的引用。这里的变量 l1, lp, ll1, lp1 是 LinearLayout 和 LayoutParams 变量。
`Button[] dhababtnarr = new Button[t];
ll.addView(dhababtnarr[i], lp);
ImageButton imagebutton = new ImageButton(this);
strref = FirebaseStorage.getInstance().getReference();
StorageReference stt=strref.child("image1.jpg");
Glide.with(this)
.using(new FirebaseImageLoader())
.load(stt)
.into(imagebutton);
LinearLayout ll1 = (LinearLayout) findViewById(R.id.linear);
LayoutParams lp1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ll1.addView(imagebutton, lp1);
dhababtnarr[1].setText(stt.toString());`
我还尝试使用 .getDownloadUrl() 下载 URL 并在 glide 中使用它,但 .addOnSuccessListener 和 .addOnFailureListener 永远不会被执行。为了检查这一点,我在这些侦听器中将一个字符串设置为随机“ss”值,并将我的按钮文本设置为该字符串,它不显示“ss”而是为空。
`Button[] dhababtnarr = new Button[t];
ll.addView(dhababtnarr[i], lp);
ImageButton imagebutton = new ImageButton(this);
strref = FirebaseStorage.getInstance().getReference();
StorageReference stt=strref.child("image1.jpg");
String URI="";
stt.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
URI="s";
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
URI="s";
}
});
Glide.with(this)
.load(URI)
.into(imagebutton);
LinearLayout ll1 = (LinearLayout) findViewById(R.id.linear);
LayoutParams lp1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ll1.addView(imagebutton, lp1);
dhababtnarr[1].setText(URI);`
【问题讨论】:
标签: android google-cloud-firestore android-glide