android - How to get a arraylist<bitmap> from gridview -
i setting shuffled arraylist in grid view after rearranging want arraylist in order there in gridview . used getchildat(position) returning view.
here code:
(int = 0; < smallimages.size(); i++) { // arraylist<view>bh=new arraylist<>(9); beforeshuffle.add(smallimages.get(i)); // smallimageadapter ad=new smallimageadapter(c,beforeshuffle); } collections.shuffle(smallimages); image_grid.setadapter(new smallimageadapter(this, smallimages)); // image_grid.setadapter(new smallimageadapter()); image_grid.setnumcolumns((int) math.sqrt(smallimages.size())); image_grid.setonitemclicklistener(new adapterview.onitemclicklistener() { int counter = 0; int firstclick; @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { counter++; if (counter % 2 == 0) { firstclick = position; bitmap data1 = smallimages.get(position); } else { bitmap swapimage = smallimages.get(position); smallimages.set(position, smallimages.get(firstclick)); smallimages.set(firstclick, swapimage); image_grid.invalidateviews(); } // arraylist<view>h=new arraylist<view>(9); (int i=0;i<smallimages.size();i++) { aftershuffle.set(i, smallimages.get(i)); } } });
this aftershulffle not in same order images place in grid view. when check
beforeshuffle.get(1).sameas(aftershuffle.get(1))
it returns false
you can use settag()
, gettag()
on view store custom class objects , ex: imageview.settag(person)
.
later can call person person = (person)getchildat(position).gettag()
https://developer.android.com/reference/android/view/view.html#settag(java.lang.object)
Comments
Post a Comment