So, I have a custom GalleryAdapter where I stream images from web with the help of an Async ImageLoading Library via ajax calls (lib name is Aquery)
.
With the images those I stream from web, I have a corresponding audio track also, with every image and hence that has to be called asynchronously when the image is loaded same time.
i.e.
image file -> http://myserver.com/img1.png
sound track -> http://myserver.com/img1.mp3
Point number 1 , I do this whole thing inside my custom
ImageAdapter
. Shall I call another thread from within mygetView
method ?What I am doing -> The
getView()
method gets called 2 times can I control it to get called only once because it shouldn't as the track gets played multiple times based on its call?
This is my Custom Adapter class
private class MainImageAdapter extends ArrayAdapter<String> {
List<String> pagedImages;
private Context context;
public MainImageAdapter(Context context,int resid, List<String> objects ) {
super( context, resid, objects );
this.context=context;
this.pagedImages=objects;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return pagedImages.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return pagedImages.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return pagedImages.get(position).hashCode();
}
@SuppressWarnings("deprecation")
public View getView(final int position, View convertView, ViewGroup parent) {
View v;
if ( convertView == null ) {
v = LayoutInflater.from(context).inflate(R.layout.imagebook, parent, false);
} else {
v = convertView;
}
System.out.println("getview called with"+position);
final ImageView im=(ImageView) v.findViewById(R.id.pagedimage);
positionMusic=position;
aq.id(im).image(pagedImages.get(position), true, true, 0, 0, new BitmapAjaxCallback(){
@Override
public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status){
iv.setImageBitmap(bm);
//This should be called only once somehow
mPlayer = MediaPlayer.create(MainActivity.this, Uri.parse(pagedImages.get(position).replace(".png", ".mp3")));
mPlayer.start();
}
});
return v;
}
}
fill_parent
, I expect it to run only once, But its not happening. – Upwards