android - cannot execute int data on method? -
i have used code the android documentation , there's 1 thing doesn't seem work. cannot execute int data on bitmapworkertask because cannot resolve symbol. method:
public boolean cancelpotentialwork(int data, imageview imageview) { final bitmapworkertask bitmapworkertask = getbitmapworkertask(imageview); if (bitmapworkertask != null) { final int bitmapdata = bitmapworkertask.data; //this line gives me error // if bitmapdata not yet set or differs new data if (bitmapdata == 0 || bitmapdata != data) { // cancel previous task bitmapworkertask.cancel(true); } else { // same work in progress return false; } } // no task associated imageview, or existing task cancelled return true; }
in case necessary, i'll provide other methods well:
class asyncdrawable extends bitmapdrawable { objectadapter oa; bitmap bm; private final weakreference<bitmapworkertask> bitmapworkertaskreference; private int data; private imageview imageview; public asyncdrawable(resources res, bitmap bitmap, bitmapworkertask bitmapworkertask) { super(res, bitmap); bitmapworkertaskreference = new weakreference<bitmapworkertask>(bitmapworkertask); } public bitmapworkertask getbitmapworkertask() { return bitmapworkertaskreference.get(); } public void loadbitmap(int resid){ bm = getbitmap(); imageview imageview = oa.getpos(); if (cancelpotentialwork(resid, imageview)) { final bitmapworkertask task = getbitmapworkertask(imageview); final asyncdrawable asyncdrawable = new asyncdrawable(resources.getsystem(), bm, task); imageview.setimagedrawable(asyncdrawable); task.execute(resid); } } public boolean cancelpotentialwork(int data, imageview imageview) { final bitmapworkertask bitmapworkertask = getbitmapworkertask(imageview); if (bitmapworkertask != null) { final int bitmapdata = bitmapworkertask.data; // if bitmapdata not yet set or differs new data if (bitmapdata == 0 || bitmapdata != data) { // cancel previous task bitmapworkertask.cancel(true); } else { // same work in progress return false; } } // no task associated imageview, or existing task cancelled return true; } private static bitmapworkertask getbitmapworkertask(imageview imageview) { if (imageview != null) { final drawable drawable = imageview.getdrawable(); if (drawable instanceof asyncdrawable) { final asyncdrawable asyncdrawable = (asyncdrawable) drawable; return asyncdrawable.getbitmapworkertask(); } } return null; } class bitmapworkertask extends asynctask<integer, void, bitmap> { imageview imageview; objectadapter oa; @override protected bitmap doinbackground(integer... params) { return null; } @override protected void onpostexecute(bitmap bitmap) { imageview = oa.getpos(); if (iscancelled()) { bitmap = null; } if (imageview != null && bitmap != null) { final imageview imageview = oa.getpos(); final bitmapworkertask bitmapworkertask = getbitmapworkertask(imageview); if (this == bitmapworkertask && imageview != null) { imageview.setimagebitmap(bitmap); } } } } }
i have no idea why problem occurring, think might simple.
thanks in advance!
vidal
the field data private should add getter or change field accessibility public
Comments
Post a Comment