In my android app I am using a tab swipe view having 4 tabs first 2 tabs displays text, in next 2 tabs I need to display bitmap images which I get from server after some background processing.Problem is bitmaps object are available in the list but not displaying.
Please see the below code
public class PhotoBeforeFoe extends Fragment {
ImageView imageView;
ExistingData existingData;
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
int count;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.photos, container, false);
ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.photo_pager);
imageView= new ImageView(getActivity());
String[] imagePath=getArguments().getStringArray("beforeImage");
ImageLoader imageLoader = new ImageLoader(getActivity());
bitmaps=imageLoader.getImageFromTheURL(imagePath,0,imageView);
/* int i=0;
for(Bitmap b :bitmaps){
if(bitmaps.get(i)!=null)
d[i]=new BitmapDrawable(getResources(),bitmaps.get(i));
else
break;
i++;
}*/
//Drawable d = new BitmapDrawable(getResources(),bitmaps.get(0));
System.out.println(d.length);
count=bitmaps.size();
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
adapter.notifyDataSetChanged();
return rootView;
}
private class ImagePagerAdapter extends PagerAdapter {
@Override
public int getCount() {
//this.notifyDataSetChanged();
return d.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = PhotoBeforeFoeFragment.this.getActivity();
ImageView imageView = new ImageView(context);
imageView.setImageBitmap(bitmaps.get(position));
// imageView.setImageDrawable(d[position]);
((ViewPager) container).addView(imageView);
return imageView;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
}
Please provide inputs I m stuck here.
If you load your images in onCreateView
by async processing, they cannot be displayed at the moment because they have not loaded. If you want to set it in instantiateItem
, you need to refresh your adapter's item after image loaded.
The solution is to delete all your image loading code and use Picasso loader in instantiateItem
:
Picasso.with(context).load(/*your url*/url).into(/*ImageView*/imgView);