Skip to content

Instantly share code, notes, and snippets.

@aldakur
Last active July 15, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aldakur/a30b477f95a93e9f633f7b03235eacaa to your computer and use it in GitHub Desktop.
Save aldakur/a30b477f95a93e9f633f7b03235eacaa to your computer and use it in GitHub Desktop.
This class contain a thread that run a log every 3 seconds
// [ES] Hilo dormilón
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ThreadSleepyhead extends AppCompatActivity {
TextView texto;
Button boton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
texto = (TextView) findViewById(R.id.texto);
boton = (Button) findViewById(R.id.boton);
boton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
for(int i =1; i<= 10; i++){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.d("DEBUG", String.valueOf(i)); //This runs every 3 seconds
}
}
}).start();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment