Last active
August 29, 2015 14:05
-
-
Save wicksome/72030b427e852b50efb5 to your computer and use it in GitHub Desktop.
더 간단한 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadHandlerTest extends Activity { | |
TextView tvTest; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_test); | |
tvTest = (TextView) findViewById(R.id.tv_test); | |
BackThread thread = new BackThread(); | |
thread.setDaemon(true); // 메인스레드와 같이 종료하기 위해서 | |
thread.start(); | |
} | |
class BackThread extends Thread { | |
@Override | |
public void run() { | |
val++; | |
mHandler.post(new Runnable() { | |
public void run() { | |
tvTest.setText(val + ""); | |
} | |
}); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
Handler mHandler = new Handler(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment