I have setup a custom gridView adapter, which looks like this
public class ImageAdapter extends BaseAdapter {
String[] urls = new String[10];
//....some code
class MyTask extends AsyncTask<Void,Void,Void>{
@Override
protected Void doInBackground(Void... arg0) {
//perform a get request and fill up the "urls" array by 10 values..
return null;
}
}
public View getView(int position, View convertView, ViewGroup parent) {
new MyTask().execute(); //execute AsyncTask
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView = null;
if (convertView == null) {
gridView = new View(context);
// get layout from grid_layout.xml
gridView = inflater.inflate(R.layout.grid_layout, null);
final ImageButton grid_art = (ImageButton) gridView.findViewById(R.id.grid_art);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).build();
imageloader = ImageLoader.getInstance();
imageloader.init(config);
imageloader.loadImage(blog_urls[position], new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
grid_art.setImageBitmap(loadedImage);
}
});
} else {
gridView = (View) convertView;
}
return gridView;
}
@Override
public int getCount() {
return urls.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
the adapter loads 10 image url's in an asynctask and stores it into the urls array.
I am using universal image loader to download and load images found at the urls into an imagebutton as background,
however only one imagebutton gets the background and the rest are blank.