skip to Main Content

Glide won’t load the images I have linked with the products on my RecyclerView. The images should be pulled from my PHP MySQL database. Not really sure what I did wrong. Please help

I’ve tried a few solutions I found on the web but none of them worked for me.

private String image;

The above is the string identifier from my product list

 //loading the image
    Glide.with(mCtx)
            .load(product.getImage())
            .into(holder.imageView);
    holder.textViewPlateNumber.setText(product.getPlatenumber());
    holder.textView1.setText(product.getMake());
    holder.textView2.setText(product.getModel());
    holder.textView3.setText(product.getYear());
    holder.textViewName.setText(product.getName());
    holder.textDate.setText(product.getDate());

    holder.recyclerid.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String platenumber = productList.get(position).getPlatenumber();
            String make = productList.get(position).getMake();
            String model = productList.get(position).getModel();
            String year = productList.get(position).getYear();
            String name = productList.get(position).getName();
            String date = productList.get(position).getDate();
            String vin = productList.get(position).getVin();
            String displacement = productList.get(position).getDisplacement();
            String fueltype = productList.get(position).getFueltype();
            String transmission = productList.get(position).getTransmission();
            String mileage = productList.get(position).getMileage();
            String ownerorcompany = 
     productList.get(position).getOwnerorcompany();
            String homeorcompanyaddress = 
  productList.get(position).getHomeorcompanyaddress();
            String contactnumber = 
 productList.get(position).getContactnumber();
             String emailaddress = productList.get(position).getEmailaddress();
            String facebook = productList.get(position).getFacebook();
            String image = productList.get(position).getImage();

The above is the code I used to show the images of each item off my adapter.

 <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/imageView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:src="@drawable/car_avatar"
            app:civ_border_color="@color/cta"
            app:civ_border_width="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/guideline17"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

The above is how the image should be laid out in my xml file. The rest of the items saved on my php sql show up on the list except the images. Here is what my php file looks like:

$vehicle = array(); 
while ($row=mysqli_fetch_array($sql)) {
 $temp = array();



 $temp['id'] = $row['VehicleID']; 
 $temp['platenumber'] = $row['PlateNumber']; 
 $temp['make'] = $row['Make']; 
 $temp['model'] = $row['Model']; 
 $temp['year'] = $row['Year']; 
 $temp['name'] = $row['OwnerorCompany']; 
 $temp['date'] = $row['AddDate']; 
 $temp['image'] = $row['vehicleImage'];
 $temp['vin'] = $row['Vin'];
 $temp['displacement'] = $row['Displacement']; 
 $temp['fueltype'] = $row['FuelType'];
 $temp['transmission'] = $row['Transmission'];
 $temp['mileage'] = $row['Mileage'];
 $temp['ownerorcompany'] = $row['OwnerorCompany'];
 $temp['homeorcompanyaddress'] = $row['HomeorCompanyAddress'];
 $temp['contactnumber'] = $row['ContactNumber'];
 $temp['emailaddress'] = $row['EmailAddress'];
 $temp['facebook'] = $row['FacebookID'];

 array_push($vehicle, $temp);


 }
 echo json_encode($vehicle);
 //}
 ?>

And this is how the images are saved on my database:

    $photo = $_POST['photo'];

    $id=uniqid();

    $path = "vehicle_upload/$id.jpeg";
    $finalpath = "http://192.168.0.10/widevalueautoInc 
    2/server/api/".$path;

When I run the app, all goes well except the images not showing up on the list. This is the java code I used to save the image and the size.

 private void addVehicle(String stringImage) {
 }

public String getStringImage(Bitmap bitmap){
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);

    byte[] imageByteArray = byteArrayOutputStream.toByteArray();
    String encodedImage = Base64.encodeToString(imageByteArray, 
 Base64.DEFAULT);
    return encodedImage;
}
}

2

Answers


  1. remove circular imageview and use default image view, to use circle crop .. use Glide circle crop function….

    Glide.with(context).load("dddd").apply(RequestOptions.circleCropTransform()).into(imageview);
    
    Login or Signup to reply.
  2. Just make a common method as below in your utility class as below :

    public static void setCircularImageToGlide(final Context context, final CircularImageView imageView, String imageUrl) {
            Glide.with(context).load("" + imageUrl).asBitmap().placeholder(R.drawable.ic_photo_placeholder).transform(new CircleTransform(context)).into(new BitmapImageViewTarget(imageView) {
                @Override
                protected void setResource(Bitmap resource) {
                    RoundedBitmapDrawable circularBitmapDrawable =
                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                    circularBitmapDrawable.setCircular(true);
                    imageView.setImageDrawable(circularBitmapDrawable);
                }
            });
        }
    

    I have passed CircularImageView as an argument to method single you are using CircularImageView instead of simple ImageView.

    Call it as below wherever you need to set image in to your CircularImageView as below :

    CommonUtil.setCircularImageToGlide(YOUR_CONTEXT, YOUR_CIRCULAR_IMAGE_VIEW, "" + YOUR_IMAGE_URL);
    

    Am using below dependency :

    implementation 'com.github.bumptech.glide:glide:3.7.0'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search