我需要一些建议。 我有一个ViewPager的片段。我用它作为一个有几张图片的画廊。图像从网站加载并存储在位图阵列中。管理片段,公共静态viewpager
起初我用..
public class GalleryPageAdapter extends PagerAdapter {
public GalleryPageAdapter(){
}
public Object instantiateItem(View collection, int position) {
}
...
//all other methods
}
但是,instatiateItem等方法现在已过时...... 我做了一些研究的跟随其他职位 Class extending Fragment - error says make sure class name exists, is public, and has an empty constructor that is public和 Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public
现在,它的工作原理没有错误
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;
}
}
而且,一如既往,这里是我的具体问题
- 由于类和片段的方法是静态的,它需要BitmapDrawable数组是静态的,它拥有几images.It是罚款,使BitmapDrawable阵列“空”时活动被破坏以释放内存? (片段被重新填充并被其他活动使用)
- 我最后的代码不需要静态类或静态数组。保持代码不变,它被弃用是好的吗?
- 这意味着将代码保留在不推荐的版本中?
提前,比你的时间和注意。
我原来的代码是完全按照你贴一个。 感谢您的文章。 我会保留这种情况下的旧代码,并在主导航菜单中使用新方法进行一些实验。 谢谢! – UrielUVD