2

hi im still new to android i was displaying some dummy images in a grid view, i have a custom adapter that uses a view holder, it puts a string array and type array into an array list and displays it in the gridview this all works fine, then i realised my images i wanted to use were far too large and found the picasso library, seems very powerful and easy to use but im unsure what to pass into the load method as it wants a type array and my type array is in an array list im sure this is a simple fix but i cant see it, my images are in the app

here is my imageId and viewholder class

 class imageIds
{
    int imageId;
    String imageNames;

    imageIds(int imageId, String imageNames)
    {
        this.imageId = imageId;
        this.imageNames = imageNames;
    }
}
class ViewHolder
{
    ImageView myView;
    ViewHolder(View view){
        myView = (ImageView) view.findViewById(R.id.imageView);
    }
}

this is the beginning of my adapter where i declare and initialize my arrays

 class myAdapter extends BaseAdapter{
        ArrayList<imageIds> list;
    Context context;
    myAdapter(Context context)
    {
        this.context = context;
    list = new ArrayList<imageIds>();
    Resources res = context.getResources();
    String[] tempWallpaperNames = res.getStringArray(R.array.wallpaper_list);

        int[] tempWallPaperImages = {R.drawable.ic_home,R.drawable.ic_photos,R.drawable.ic_home,
                R.drawable.ic_photos,R.drawable.ic_photos,R.drawable.ic_photos,R.drawable.ic_home,
                R.drawable.ic_home,R.drawable.ic_photos,R.drawable.ic_home};
            for (int i = 0; i<10;i++)
            {
                imageIds tempWallpaper = new imageIds(tempWallPaperImages[i],tempWallpaperNames[i]);
                list.add(tempWallpaper);
            }
    }

and here is my adapter get view method

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View row = convertView;
        ViewHolder holder = null;
        if (row == null){

            LayoutInflater inflater = (LayoutInflater)  
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.grid_images,parent,false);
            holder = new ViewHolder(row);
            row.setTag(holder);
        }
        else{
          holder = (ViewHolder) row.getTag();
        }

        imageIds wallPapers = list.get(position);
        holder.myView.setImageResource(wallPapers.imageId);

        holder.myView.setTag(wallPapers);

        Picasso.with(getActivity())
                .load(imageIds[position])
                .placeholder(R.drawable.ic_photos)
                .error(R.drawable.ic_drawer)
                .noFade().resize(120,120)
                .centerCrop().into(holder.myView);
        return holder.myView;


        return row;
    }
}

android studio is telling me an expression is expected here

.load(imageIds[position])

thanks for any help

1 Answer 1

1

load expects the actual image filename or a resourceId.

i'm assuming the imageNames holds the location/filename or you could use the imageId.

change

.load(imageIds[position])

To

.load(imageIds[position].imageNames) or .load(imageIds[position].imageId)

Update

You are already using list.get(position) so you are only returning one item in the wallPapers variable.

So the code should be .load(wallPapers.imageId)

Sign up to request clarification or add additional context in comments.

6 Comments

Okay that makes sense thank you but still saying expression expected, tried a couple variations as I thought it may be .imageId no success
@MartinSeal Can you share the variations?
@MartinSeal wow .. i can see the error now ... i'm updating my answer now.
@MartinSeal I've updated my answer. you should use .load(imageIds.imageId)
That's awesome thank you although now I have a non static field cannot be referenced from a static context error @scartag
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.