Android Cannot execute setListAdapter() user thread.

Posted by Ameya on Stack Overflow See other posts from Stack Overflow or by Ameya
Published on 2010-05-29T09:49:11Z Indexed on 2010/05/29 9:52 UTC
Read the original article Hit count: 476

Filed under:

I got a class

class MyClass extends ListActivity implements Runnable{



ArrayList array;


 onCreate(){



Thread thread = new Thread(this);

hread.start();



}



@Overriding

void run(){

addAnElement();

}

void addAnElement(){
if(null==array)
array=new ArrayList();
array.add("Some junck string");
this.setListAdapter(.....,array);
}



}

on executing in emulator get error

ERROR/AndroidRuntime(288): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

I know we cannot access UI calls from user thread.

Can anyone help.

© Stack Overflow or respective owner

Related posts about android