android - can not render online resources or simple text in canvas -


i have view want display resources online. create subclass of android.view.view , override dispatchdraw method:

public class tview extends view {     asynchttpclient client = new asynchttpclient();     private paint p = new paint();      public tview(context context) {         super(context);     }      @override     protected void dispatchdraw(final canvas canvas) {         client.get("http://developer.android.com/assets/images/dac_logo.png", new binaryhttpresponsehandler() {             @override             public void onsuccess(byte[] arg0) {                 dorender(canvas, arg0);             }         });         super.dispatchdraw(canvas);     }      private void dorender(canvas c, byte[] data) {         log.d("xx", "data length :" + data.length);         c.drawtext("hello", 10, 10 + p.gettextsize(), p);         bitmap bmp = bitmapfactory.decodebytearray(data, 0, data.length);         bitmapdrawable bd = new bitmapdrawable(bmp);         bd.draw(c);     } } 

however following codes not work.

i got log message :

04-18 19:10:44.933: d/xx(1258): data length :2170 

it seems data downloaded. canvas not render it.

what problem?

btw,i use asychttpclient simplify data request.

i asker of post. , find said solution. ( not if best works).


it seems caused asynchronous thread when tried request data asynchttpclient. , once requesting thread start, ui thread complete , returned back, , canvas have got out of scope.

then when data returned back, canvas not work more.

btw, still hope convinced answer.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -