android - Dynamically display imagebuttons in AsyncTask -
so retrieving images parse , dynamically displaying them in scrollview linearlayout, can't seem add clicklistener or add them view. here's have:
mytaskparams params = new mytaskparams(drinklist.get(j).getstring("name"), data, lpos, drinklist.get(j).getobjectid(), j); mytask mytask = new mytask(); mytask.execute(params);
and in pass data , try adding imagebutton view.
private static class mytaskparams { string name; byte[] data; int lpos; string id; int j; public mytaskparams(string name, byte[] data, int lpos, string id, int j) { this.data = data; this.name = name; this.lpos = lpos; this.id = id; this.j = j; } } private class mytask extends asynctask<mytaskparams, void, mytaskparams> { @override protected mytaskparams doinbackground(mytaskparams... params) { string name = params[0].name; byte[] data = params[0].data; int lpos = params[0].lpos; string id = params[0].id; int j = params[0].j; log.d("doinbackground", data.tostring()); bmp = bitmapfactory.decodebytearray(data, 0, data.length); btn = new imagebutton(getactivity()); btn.setid(j); btn.settag(name); btn.setimagebitmap(bmp); btn.setbackgrounddrawable(null); btn.setmaxheight(100); btn.setmaxwidth(100); btn.setonclicklistener(new drinkbuttonlistener(getactivity(), lpos, id)); llayout[lpos].addview(btn); return null; } }
why can't create clicklistener or add button view? error:
"only original thread created view hierarchy can touch views"
y ou can't touch views in other tread main.
if want manipulate view can post runnable view like
myview.post(new runnable(...));
Comments
Post a Comment