Saturday, 15 September 2012

android - Duplicates of thumbnails in GridView -



android - Duplicates of thumbnails in GridView -

i'm looking help solve problem why gridview don't show right number of thumbnails , instead shows lot of duplicates of thumbnails in groups? , when scroll list of thumbnails en downwards , homecoming top, order of images changes time.

anyone knows reason , how solve it? perhaps there improve way create gridview of thumbnails? or phone? utilize samsung young android version 2.3.3. read htc had similar problem.

i preciate help able go on work. thanks!

below code:

public class mainactivity extends activity { cursor cursor; int indexcolumn; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // array columns access string[] projection = {mediastore.images.thumbnails._id}; // cursor object cursor = managedquery(mediastore.images.thumbnails.external_content_uri, projection, null, null, mediastore.images.thumbnails.image_id); // number of columns indexcolumn = cursor.getcolumnindexorthrow(mediastore.images.thumbnails._id); gridview gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new imageadapter(this)); // send class constructor /* gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(mainactivity.this, "" + position, toast.length_short).show(); } }); */ gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { // sending image id fullscreenactivity intent = new intent(getapplicationcontext(), fullimageactivity.class); // passing array index i.putextra("id", position); startactivity(i); } }); } // nested class public class imageadapter extends baseadapter { private context mcontext; // constructor public imageadapter(context c) { mcontext = c; } public int getcount() { homecoming cursor.getcount(); } public object getitem(int position) { homecoming position; } public long getitemid(int position) { homecoming position; } // create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) { imageview imageview; if (convertview == null) { // if it's not recycled, initialize attributes imageview = new imageview(mcontext); // move cursor current position cursor.movetoposition(position); // current value value requested column int imageid = cursor.getint(indexcolumn); // set content of image imageview.setimageuri(uri.withappendedpath(mediastore.images.thumbnails.external_content_uri, "" + imageid)); imageview.setlayoutparams(new gridview.layoutparams(85, 85)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); } else { imageview = (imageview) convertview; } //imageview.setimageresource(mthumbids[position]); homecoming imageview; } } }

replace getview method following:

// create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) { imageview imageview; if (convertview == null) { // if it's not recycled, initialize attributes imageview = new imageview(mcontext); } else { imageview = (imageview) convertview; } // move cursor current position cursor.movetoposition(position); // current value value requested column int imageid = cursor.getint(indexcolumn); // set content of image imageview.setimageuri(uri.withappendedpath(mediastore.images.thumbnails.external_content_uri, "" + imageid)); imageview.setlayoutparams(new gridview.layoutparams(85, 85)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); homecoming imageview; }

tell me if works..

android gridview thumbnails

No comments:

Post a Comment