android - my application crash in ListView Event orThread -



android - my application crash in ListView Event orThread -

lst.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, final view view,int position, long id) { //btnsub button btnsub.setenabled(true); toast.maketext(getapplicationcontext(), "before start()", toast.length_short).show(); for(int i=0;i<j;i++){ //lst listview object view vtmp = lst.getchildat(i); if(vtmp !=null){ if(i==lst.getcheckeditemposition()){ //cindex int var cindex=lst.getcheckeditemposition(); }else{ } } } new thread() { public void run() { toast.maketext(getapplicationcontext(), "in thread ", toast.length_long).show(); try{ thread.sleep(1000); lst.getchildat(cindex).setbackgroundcolor(color.blue); }catch(exception e){ toast.maketext(getapplicationcontext(), "thread generate: "+e.getmessage(), toast.length_long).show(); } } }.start(); toast.maketext(getapplicationcontext(), "after start()", toast.length_short).show(); } });

you can't update ui in worker thread. modify code:

new thread() { public void run() { try{ thread.sleep(1000); mactivity.runonuithread(new runnable() { public void run() { toast.maketext(getapplicationcontext(), "in thread ", toast.length_long).show(); lst.getchildat(cindex).setbackgroundcolor(color.blue); } }); }catch(exception e){ } } }.start();

a improve way utilize handler, can read - communicating ui thread

android multithreading listview

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -