Android Photo Album

0

I'm putting together an album, and with the code below, I can see all the images:

@Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        view = getLayoutInflater().inflate(R.layout.grid_item_layout , viewGroup, false);
        ImageView image = (ImageView) view.findViewById(R.id.image);
        image.setImageURI(Uri.parse(getItem(position).toString()));

        return view;
    }

Sointhisway,thememoryofthedevicerunsouttoofast.SoIfoundtwoAPIsthatshoulddothesamejob:PicassoandGlide.Butbyusingtheselines,theimagesdonotappearinImageView.

@OverridepublicViewgetView(intposition,Viewview,ViewGroupviewGroup){view=getLayoutInflater().inflate(R.layout.grid_item_layout,viewGroup,false);ImageViewimage=(ImageView)view.findViewById(R.id.image);//Nenhumadasduasabaixofunciona//Picasso.with(getApplication()).load(Uri.parse(getItem(position).toString())).into(image);//Glide.with(GaleriaActivity.this).load(Uri.parse(getItem(position).toString())).into(image);returnview;}

Result:

How can I resolve this?

    
asked by anonymous 03.08.2017 / 01:02

2 answers

0

The error is that you are using Uri.parse . You should actually enter the URL directly as a parameter of the .load() method in Glide or Picasso. See below for the correct one:

Glide.with(this)
    .load("https://www.w3schools.com/css/paris.jpg")
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(ivImgGlide);

So as you are passing a list of URLs, I assume, you should do it this way:

Glide.with(this)
        .load(getItem(position).toString())
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(ivImgGlide);
    
03.08.2017 / 17:01
0

Try:

Uri uri = Uri.fromFile(new File(getItem(position).toString()));
Glide.with(context).load(uri).into(image);

A tip:

Inflating a layout for each item in the adapter can be costly and will not make the scroll smooth. I recommend using the default ViewHolder

    
03.08.2017 / 13:50