【发布时间】:2015-07-19 10:46:02
【问题描述】:
你好,我还是安卓新手 我在网格视图中显示了一些虚拟图像,我有一个使用视图持有者的自定义适配器,它将字符串数组和类型数组放入数组列表中并在网格视图中显示这一切都很好, 然后我意识到我想要使用的图像太大了,并找到了 picasso 库,看起来非常强大且易于使用,但我不确定将什么传递给 load 方法,因为它需要一个类型数组并且我的类型数组在一个数组中列出我确定这是一个简单的修复,但我看不到它, 我的图片在应用程序中
这是我的 imageId 和 viewholder 类
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 studio 告诉我这里应该有一个表达式
.load(imageIds[position])
感谢您的帮助
【问题讨论】: