스레드에 대한 개념이 전무해 초급예제를 보고 따라하는데 도통 이해가 안되는 부분이
있습니다.
아래는 스레드를 사용해
[incress]버튼을 누르면 숫자가 증가하는 아주 단순한 프로그램입니다.
그런데 Button 을 누르는데 왜 버든id값도 없고 버튼 클릭리스너도 사용안하는데
어떻게 실행시키면 버튼 누를때마다 증가가 될까요?
스레드에 버튼객체 연결시킨 흔적(?)도 없는데 말입니다 ㅠㅠ
아시는분 있나요?
//* Thread 객체 사용
public class ThreadTest extends Activity {
int mMainValue = 0;
int mBackValue = 0;
TextView mMainText;
TextView mBackText;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.threadtest);
mMainText = (TextView)findViewById(R.id.mainvalue);
mBackText = (TextView)findViewById(R.id.backvalue);
BackThread thread = new BackThread();
thread.setDaemon(true);
thread.start();
}
public void mOnClick(View v) {
mMainValue++;
mMainText.setText("MainValue : " + mMainValue);
mBackText.setText("BackValue : " + mBackValue);
}
class BackThread extends Thread {
public void run() {
while (true) {
mBackValue++;
//mBackText.setText("BackValue : " + mBackValue);
try { Thread.sleep(1000); } catch (InterruptedException e) {;}
}
}
}
}