java - android - viewpager OutOfMemoryError -
i have problem. want image url json , setting viewpager. tried drawable
folder, large images causing problems. if image small, not have problem. how can large images? benefited article : enter link description here
galleryactivity
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_gallery); viewpager viewpager = (viewpager)findviewbyid(r.id.viewpa); galleryadapter ga = new galleryadapter(this); viewpager.setadapter(ga); }
gallery adapter (extending pageradapter)
context context; private int[] galimages = new int[] { r.drawable.one, r.drawable.two, r.drawable.three }; galleryadapter(context context){ this.context=context; } @override public int getcount() { return galimages.length; } @override public boolean isviewfromobject(view view, object object) { return view == ((imageview) object); } @override public object instantiateitem(viewgroup container, int position) { imageview imageview = new imageview(context); int padding = context.getresources().getdimensionpixelsize(r.dimen.padding_medium); imageview.setpadding(padding, padding, padding, padding); imageview.setscaletype(imageview.scaletype.center_inside); imageview.setimageresource(galimages[position]);// error on line when large image ((viewpager) container).addview(imageview, 0); return imageview; } @override public void destroyitem(viewgroup container, int position, object object) { ((viewpager) container).removeview((imageview) object); }
and logcat outputs
java.lang.outofmemoryerror @ android.graphics.bitmapfactory ...
Comments
Post a Comment