Saturday, 7 September 2013

FAB ATRES PRODUI.PHARMAC.USAGE

FAB ATRES PRODUI.PHARMAC.USAGE

Can I use a thread for increment a counter and shows it in a frame of
Android activity.
Public class MainActivity extendsActivity {
TextView counter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = (TextView) findViewById(R.id.TV_counter);
Thread t = new Thread() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
for (int i = 0; i < 5; i++) {
try {
counter.setText("" + i);
System.out.println("Value of i= " + i);
sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
};
t.start();
}
}
I wrote this code, but it run properly in console, but the text view
displays i=4 in the terminal, I modified the time to sleep(3000) and the
problem persists.

No comments:

Post a Comment