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. 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? :)
Take a look at the Picasso library: https://github.com/square/picasso
It takes care of everything you need. It loads the image into your ImageView and even supports caching. It's very easy to use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.