package com.hb.adt0303;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Last extends Activity implements Runnable {
int su1 = 0, su2 = 0, su3 = 0;
TextView tv1, tv2, tv3;
Button bt1, bt2, bt3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_last);
tv1 = (TextView) findViewById(R.id.msg1);
tv2 = (TextView) findViewById(R.id.msg2);
tv3 = (TextView) findViewById(R.id.msg3);
bt1 = (Button) findViewById(R.id.btnOne);
bt2 = (Button) findViewById(R.id.btnTwo);
bt3 = (Button) findViewById(R.id.btnThr);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// tv1.setText("su1="+su1);
//2초 간격으로 1씩 증가
// Thread.sleep(2000);
Thread th = new Thread(Last.this);
th.start();
}
});
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
su2 = su2 + 5;
tv2.setText("su2=" + su2);
}
});
//3번째 버튼
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
su3 = su3 + 10;
tv3.setText("su3=" + su3);
}
});
}
public void run() { //run 메소드안에
while(true) {
// su1 = su1 + 1;
// tv1.setText("su1=" + su1);
runOnUiThread(new Runnable() {
@Override
public void run() {
su1 = su1 + 1;
tv1.setText("su1=" + su1);
}
});
try {
Thread.sleep(2000);
} catch (Exception e) {}
}
};
}
RECENT COMMENT