[英]Android: Using ImageLoader in my Project?
So I'm a bit confused on how to properly implement an ImageLoader in my projects since most of the projects I refereed to dealt with creating a globally accessible ImageLoader object and accessing it through the Adapter. 因此,我对如何在项目中正确实现ImageLoader感到困惑,因为我提到的大多数项目都涉及创建可全局访问的ImageLoader对象并通过Adapter访问它。 However my class is fixed like this:
但是我的班级是这样固定的:
public class ProductGridInflator extends ArrayAdapter<Product>{
private int[] Imageid;
ArrayList<Product> dbProducts;
Context ctx;
int resource;
ArrayList<Image> urlArr = new ArrayList<Image>();
ArrayList<Image> dbImages = new ArrayList<Image>();
public ProductGridInflator(Context context, int resource,ArrayList<Product> objects, ArrayList<Image> obj) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
this.dbProducts = objects;
this.ctx = context;
this.resource = resource;
this.dbImages = obj;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if(dbProducts.size() == 0){
return 0;
}else{
return dbProducts.size();
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View child = convertView;
RecordHolder holder;
LayoutInflater inflater = ((Activity) ctx).getLayoutInflater(); // inflating your xml layout
if (child == null) {
child = inflater.inflate(R.layout.grid_single, parent, false);
holder = new RecordHolder();
holder.productName = (TextView) child.findViewById(R.id.grid_text); // fname is the reference to a textview
holder.image = (ImageView) child.findViewById(R.id.grid_image);
child.setTag(holder);
}else{
holder = (RecordHolder) child.getTag();
}
final Product user = dbProducts.get(position);
holder.productName.setText(user.getNAME());
for(int i=0;i<dbImages.size();i++)
{
if(dbImages.get(i).PID.equals(user.PID))
{
//holder.image is my image holder
//This is where the URL should be accessed and image to be added
String URL = dbImages.get(i).URL;
}
else
continue;
}
return child;
}
So how do I implement a ImageLoader in this code and access the URL I specified guys? 那么,如何在此代码中实现ImageLoader并访问我指定的URL? :)
:)
Take a look at the Picasso library: https://github.com/square/picasso 看看Picasso库: https : //github.com/square/picasso
It takes care of everything you need. 它照顾您需要的一切。 It loads the image into your ImageView and even supports caching.
它将图像加载到您的ImageView中,甚至支持缓存。 It's very easy to use.
它很容易使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.