android - How may i use the thread in my program? -


i want move image on screen using thread have tried not working fine due improper code of thread. able image , want move image on screen in code want move ovalshaped image , dont want must effect jerry image problem thread implementing on margenmaxx, margenxy maximum width , height

    public class animatedview extends imageview {             public animatedview(context context) {                 super(context);  resources res = context.getresources();             drawable = res.getdrawable(r.drawable.jerry);         mdrawable =  new shapedrawable(new ovalshape());                 mdrawable.getpaint().setcolor(0xffffac23);     }       protected void ondraw(final canvas cc) {             final context context = null; drawable.setbounds(x , y , x + width, y + height);             drawable.draw(cc);             invalidate();                 thread thread = new thread()                             {                                 @override                                 public void run() {                                     try {                                         while(i<=margenmaxx && j<=margenmaxy) {                                             sleep(100);                                            // context.runonuithread(new runnable() {                                             //handler.post(r);                                             runonuithread(new runnable() {                                           @override                                          public void run() {                                                  mdrawable.setbounds(i, j ,i+ width, i+ height);                                                  mdrawable.draw(cc);                                          }                                      });                                             //invalidate();                                             i=i+10;                                             j=j+10;                                         }                                     } catch (interruptedexception e) {                                         e.printstacktrace();                                     }                                 }                             };                              thread.start();              } 

you have update ui within ui thread. try this, not tested should work

protected void ondraw(final canvas cc) {     thread thread = new thread()                 {                     @override                     public void run() {                         try {                             while(i<=margenmaxx && j<=margenmaxy) {                                 sleep(100);                                 //handler.post(r);                                context.runonuithread(new runnable() {                               @override                              public void run() {                                      mdrawable.setbounds(i, j ,i+ width, i+ height);                                      mdrawable.draw(cc);                              }                          });                                 //invalidate();                                 i=i+10;                                 j=j+10;                             }                         } catch (interruptedexception e) {                             e.printstacktrace();                         }                     }                 };                  thread.start();  }} 

see this details


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -