I need some advice on this. I have a Fragment with a ViewPager. I use it as a gallery with a few images. The images are loaded from web and stored on a Bitmap array.
At first i used..
public class GalleryPageAdapter extends PagerAdapter {
public GalleryPageAdapter(){
}
public Object instantiateItem(View collection, int position) {
}
...
//all other methods
}
but, instatiateItem and other methods are now deprecated... I made some research an followed other posts Class extending Fragment - error says make sure class name exists, is public, and has an empty constructor that is public and Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public
Now it works without error
public class sEstablecimiento extends android.support.v4.app.FragmentActivity{
static BitmapDrawable iconos[];
//load bitmaps into iconos[] from web
static class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
static int position;
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
this.position=position;
return new ScreenSlidePageFragment();
}
@Override
public int getCount() {
return iconos.length;
}
}
public static class ScreenSlidePageFragment extends Fragment {
private BitmapDrawable image;
public ScreenSlidePageFragment() {
image=iconos[ScreenSlidePagerAdapter.position];
}
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView =(ViewGroup)inflater.inflate(R.layout.fragment_screen_slide_page, container, false);
ImageView icono=(ImageView)rootView.findViewById(R.id.imagen);
icono.setImageDrawable(iconos[ScreenSlidePagerAdapter.position]);
return rootView;
}
}
And, as always, here are my specific questions
- As the class and methods of the fragment are static, it needs the BitmapDrawable array to be static and it holds a few images.It is fine to make the BitmapDrawable array 'null' when the activity is destroyed to free the memory? (the fragment is refilled and used by other activities)
- My last code do not need static classes or static array. It is Fine to keep the code as it is altought it is deprecated?
- What implies keep the code in the deprecated version?
in advance, than you for your time and atention.