james6754 39 Junior Poster

Hi, I have created a new Thread in my Activity and call start on it. The run() method of the new thread runs but when I am attempting to change the UI it crashes.

Because of the above I am using runOnUiThread().

Button v = (Button) findViewById(R.id.newButton);

runOnUiThread(new Runnable(){public void run(){
		v.setText("Text for new button");}});

I have also tried using this,

MyProj.this.runOnUiThread(new Runnable(){public void run(){
		v.setText("Text for new button");}});

Every time I try to run this, the app crashes. Can anyone help me understand what is going wrong or give an example of how to change the UI from another Thread?

Thanks!

peter_budo commented: Interesting question, unfortunately I can't help. +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.