I have a viewpager that uses custom views and not fragments as pages. this custom view is basically a linearlayout with an imageview since am using my viewpager to show images.
However when screen orientation changes, everything disappears. including my imageviews. i have done research and
- Most tutorials are showing how to do this with fragments.(in my case am not using fragments) Android: Saving Fragment state in ViewPager?
My viewpager adapter is using an arraylist which contain path to image files.
Below is my viewpager's adapter.(NOTE:am using an arraylist where am adding items to it and then callingnotifyDataSetChanged
)
Below is my viewpager's adapter class
public class ViewPagerAdapter extends PagerAdapter {
private Context context;
private LayoutInflater inflater;
private ArrayList<ImagePaths> imagesArray;
public ViewPagerAdapter(Context context,ArrayList<ImagePaths> array, ){
this.context = context;
inflater =LayoutInflater.from(context);
imagesArray = array;
}
public int getCount(){
return imagesArray.size();
}
public boolean isViewFromObject(View view,Object object){
return view == object;
}
public Object instantiateItem(ViewGroup viewGroup, int position){
View view = inflater.inflate(R.layout.photo_layout, viewGroup, false);
ImageView imageView =(ImageView) view.findViewById(R.id.photoView);
final String imagePath = imagesArray.get(position);
ImageLoader.getInstance().displayImage(imagePath, imageView);
viewGroup.addView(view);
return view;
}
public void destroyItem(ViewGroup container, int position, Object object){
container.removeView((LinearLayout) object);
}
}
What do i need to do to save the state of my viewpager?