Tuesday, 15 March 2011

java - Android Grid Image Adapter skipping frames -



java - Android Grid Image Adapter skipping frames -

hey guys m developing simple app displays images in gridview , goes total screen when clicked problem is skipping frames . here code .. check out.

mainactivity

public class mainactivity extends activity { gridview gridview; private string[] web = { "string1", "string2", "string3", "string4", "string5", "string6" }; private int[] imageid = { r.drawable.image1, r.drawable.image2, r.drawable.image3, r.drawable.image4, r.drawable.5, r.drawable.image6 }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); this.requestwindowfeature(window.feature_no_title); setcontentview(r.layout.activity_main); gridview = (gridview) findviewbyid(r.id.gridview1); gridview.setadapter(new galleryimageadapter(this, web, imageid)); gridview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view v, int position, long id) { intent intentfull = new intent(getapplicationcontext(), fullscreenimage.class); intentfull.putextra("id", position); startactivity(intentfull); } }); } }

galleryimageadapter.class

public class galleryimageadapter extends baseadapter { private context mcontext; public string[] web = { "string1", "string2", "string3", "string4", "string5", "string6" }; public int[] imageid = { r.drawable.image1, r.drawable.image2, r.drawable.image3, r.drawable.image4, r.drawable.5, r.drawable.image6 }; public galleryimageadapter(context context, string[] web, int[] imageid) { mcontext = context; } @override public int getcount() { homecoming web.length; } @override public object getitem(int position) { homecoming imageid[position]; } @override public long getitemid(int position) { homecoming 0; } @override public view getview(int position, view convertview, viewgroup parent) { view grid; imageview imageview = null; layoutinflater inflater = (layoutinflater) mcontext .getsystemservice(context.layout_inflater_service); if (convertview == null) { grid = new view(mcontext); grid = inflater.inflate(r.layout.grid_single_item, null); textview textview = (textview) grid.findviewbyid(r.id.textdua); imageview = (imageview) grid.findviewbyid(r.id.imagedua); textview.settext(web[position]); imageview.setimageresource(imageid[position]); } else { grid = (view) convertview; } homecoming grid; } }

the main layout images showing in grid skip frames , when click on singleitem i.e single image (of course) works fine...

thanks !

i think getview method wrong seek right hope work fine you

@override public view getview(int position, view convertview, viewgroup parent) { view grid; imageview imageview = null; layoutinflater inflater = (layoutinflater) mcontext .getsystemservice(context.layout_inflater_service); if (convertview == null) { grid = new view(mcontext); grid = inflater.inflate(r.layout.grid_single_item, null); textview = (textview) grid.findviewbyid(r.id.textdua); imageview = (imageview) grid.findviewbyid(r.id.imagedua); } else { grid = (view) convertview; } textview.settext(web[position]); imageview.setimageresource(imageid[position]); homecoming grid; }

i think have initialize texview , imageview in adapter class , alter getview method above because converview null first time phone call first time only. hope got solution.

java android baseadapter frames skip

No comments:

Post a Comment