简体   繁体   中英

glide placeholder not showing image

android glide not showing the fetched image. its stuck at default image. am using glide version 4.7.1 here is my code bellow

 mStorageRef = FirebaseStorage.getInstance().getReference();

 mAuthUser = FirebaseAuth.getInstance();
 firebaseFirestore = FirebaseFirestore.getInstance();
 userIDM = mAuthUser.getCurrentUser().getUid();

 //getting data from firebaseFireStore
 firebaseFirestore.collection("Users").document(userIDM).get().addOnCompleteListener(new
 OnCompleteListener<DocumentSnapshot>() {
     @Override
     public void onComplete(@NonNull Task<DocumentSnapshot> task) {
         if (task.isSuccessful()){

             Toast.makeText(SetupActivity.this, "success", Toast.LENGTH_LONG).show();

             if (task.getResult().exists()){

                 Toast.makeText(SetupActivity.this, "user data exist", Toast.LENGTH_LONG).show();
                  String name = task.getResult().getString("name");
                  String image = task.getResult().getString("image");

                 RequestOptions placeHolder = new RequestOptions();
                 placeHolder.placeholder(R.mipmap.setup_user);

                 userName.setText(name);
                 Glide
                         .with(SetupActivity.this)
                         .setDefaultRequestOptions(placeHolder)
                         .load(image)
                         .into(userImage);

             }else {
                 Toast.makeText(SetupActivity.this, "user data dose'nt exist", Toast.LENGTH_LONG).show();

             }

         }else {

             String errorM = task.getException().getMessage();
             Toast.makeText(SetupActivity.this,"error"+errorM, Toast.LENGTH_LONG).show();

         }
     }
 });

Make a empty class like this

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

// new since Glide v4
@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

now use Glide like this :

GlideApp.with(SetupActivity.this)
.load(image)
.placeholder(R.mipmap.setup_user)
.into(userImage);
  RequestOptions placeholderRequest = new RequestOptions();
                        placeholderRequest.placeholder(drawable img you want);

                        Glide.with(SetupActivity.this).setDefaultRequestOptions(placeholderRequest).load(ur variable).into(ur vraiable);

在滑行中添加 .placeholder(yourimage) 它有效

Glide.with(context)
           .load(your img url)
           .into(your image place)
           .onLoadStarted(resources.getDrawable(R.drawable.your_image,null))

in newer versions

Downgrade the Glide version works for me. You can give it a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM