I'm doing an app that is increasing the seconds, later I'll add other functions, but for the moment, I mark an error at the moment that the threads start working marks me this error.
Only the original thread that created a view of the hierarchy can touch its views.
And my code is as follows
public class MainActivity extends AppCompatActivity {
TextView tv;
int seg=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.reloj);
}
boolean on=false;
public void inicia(View view){
if(!on){
tiempo.start();
on=true;
}
}
Thread tiempo=new Thread(){
public void run(){
try{
while(true){
Thread.sleep(1000);
seg++;
tv.setText(seg+"");
}
}catch (InterruptedException e){
}
}
};
}