使用毕加索库从数组列表加载图像

loading images from array list using picasso library

嗨,我对 android 还是个新手 我在网格视图中显示了一些虚拟图像,我有一个使用视图持有者的自定义适配器,它将字符串数组和类型数组放入数组列表中并将其显示在网格视图中,这一切都很好, 然后我意识到我想使用的图像太大了,发现了 picasso 库,它看起来非常强大且易于使用,但我不确定要将什么传递给加载方法,因为它需要一个类型数组,而我的类型数组在一个数组中列表我确定这是一个简单的修复,但我看不到它, 我的图片在应用程序中

这是我的 imageId 和 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);
    }
}

这是我的适配器的开始,我在其中声明并初始化我的数组

 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);
            }
    }

这是我的适配器获取视图方法

@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 工作室告诉我这里需要一个表达式

.load(imageIds[position])

感谢您的帮助

load 需要实际的图像文件名或 resourceId。

我假设 imageNames 持有 location/filename 或者你可以使用 imageId.

改变

.load(imageIds[position])

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

更新

您已经在使用 list.get(position),因此您只返回 wallPapers 变量中的一项。

所以代码应该是.load(wallPapers.imageId)