android - Shuffling in a gridview -
i having trouble shuffling images in gridview. makin npuzzle slider , can slide blank image. main problem set tags on imageview in gridviewadapter. if shuffle images, these tags stay same supposed change images. example
suppose got bitmaparraylist of bitmaps: {bm0,bm1,bm2,bm3,bm4,bm5,bm6,bm7,bm8} , set tags {0,1,2,3,4,5,6,7,8} in image adapter. if shuffle bitmap, how supposed shuffle imagetags them?
here code of imageadapter:
private arraylist<bitmap> crops; private list id; private context mcontext; public imageadapter(context c, arraylist<bitmap> crops, list id) { mcontext = c; this.crops = crops; this.id = id; } public int getcount() { return crops.size(); } public object getitem(int position) { return null; } public long getitemid(int position) { return 0; } 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); imageview.setlayoutparams(new gridview.layoutparams(85, 85)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); } else { imageview = (imageview) convertview; } imageview.setimagebitmap(crops.get(position)); imageview.settag(position); return imageview; }
}
as can see tags same, cause problems. :(
any hints tricks or tips on solving this?
ps: made list id's didn't because didn't know do
kees
you can shuffle list or other collection this
long seed = system.nanotime(); collections.shuffle(bitmaparraylist , new random(seed));
after call adapter's notifydatasetchanged method. don't need set tag of imageview.
Comments
Post a Comment