package
com.umer.runOnUiThreadExmp;
import
android.app.Activity;
import
android.os.Bundle;
import
android.widget.TextView;
public
class
RunOnUiThreadExample
extends
Activity {
/** Called when the activity is first created. */
TextView txtview;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtview=(TextView)findViewById(R.id.txtview);
myThread();
}
public
void
myThread(){
Thread th=
new
Thread(){
@Override
public
void
run(){
try
{
while
(
true
)
{
Thread.sleep(
100
);
RunOnUiThreadExample.
this
.runOnUiThread(
new
Runnable() {
@Override
public
void
run() {
// do ur UI work
txtview.setText("my name is umer and i am android developer");
}
});
}
}
catch
(InterruptedException e) {
}
}
};
th.start();
}
}
No comments:
Post a Comment