Last active
July 15, 2016 09:39
-
-
Save aldakur/a30b477f95a93e9f633f7b03235eacaa to your computer and use it in GitHub Desktop.
This class contain a thread that run a log every 3 seconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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