public class MainActivity extends AppCompatActivity {
TextView label;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but = (Button) findViewById(R.id.but);
label = (TextView) findViewById(R.id.label2);
}
public void butpress(View view){
ButPres nm = new ButPres();
nm.actionPerformed();
}
class ButPres extends Thread{
boolean prov = true;
public void actionPerformed() {
runOnUiThread(
new Runnable() {
@Override
public void run() {
while (prov) {
String time = new SimpleDateFormat("kk:mm:ss").format(Calendar.getInstance().getTime());
label.setText(time);
try {
Thread.sleep(1000);
} catch (Exception e) {
System.out.println(e);
}
}
}
}
);
}
}
}
}