Dynamically add images to Android WheelView -


i have been working on issue days now. using kankan android wheel example/library, wanting dynamically add images wheel when button pressed. image added depends on button's text. seems easy task, perhaps missing something. tried calling adapter's notifydatachangedevent() after passing , adding selected image adapter's list of cached images. debugging has showed images being added list of images, not showing on wheel. if please me out problem appreciate it!

code:

public void additem(string text) {      for(item c: item.values()){         if(c.getname().equals(text)) {             slotmachineadapter.addimage(c.getimage());             break;         }     }     slotmachineadapter.notifydatachangedevent(); } 

adapter

private class slotmachineadapter extends abstractwheeladapter {     // image size     final int image_width = 700;     final int image_height = 150;      // slot machine symbols     private final int items[] = new int[] {             r.mipmap.ic_flipper     };      // cached images     private list<softreference<bitmap>> images;      // layout inflater     private context context;      /**      * constructor      */     public slotmachineadapter(context context) {         this.context = context;         images = new arraylist<softreference<bitmap>>();         (int id : items) {             images.add(new softreference<bitmap>(loadimage(id)));         }     }      /**      * loads image resources      */     private bitmap loadimage(int id) {         bitmap bitmap = bitmapfactory.decoderesource(context.getresources(), id);         bitmap scaled = bitmap.createscaledbitmap(bitmap, image_width, image_height, true);         bitmap.recycle();         return scaled;     }      @override     public int getitemscount() {         return items.length;     }      // layout params image view     final viewgroup.layoutparams params = new viewgroup.layoutparams(image_width, image_height);      @override     public view getitem(int index, view cachedview, viewgroup parent) {         imageview img;         if (cachedview != null) {             img = (imageview) cachedview;         } else {             img = new imageview(context);         }         img.setlayoutparams(params);         softreference<bitmap> bitmapref = images.get(index);         bitmap bitmap = bitmapref.get();         if (bitmap == null) {             bitmap = loadimage(items[index]);             images.set(index, new softreference<bitmap>(bitmap));         }         img.setimagebitmap(bitmap);          return img;     }      //adds image list of images     public void addimage(int img){         images.add(new softreference<bitmap>(loadimage(img)));     } } 

because count return referenced items variable, addimage function did not change items size. try change code below , test again:

@override     public int getitemscount() {         return images.size();     } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -