Display Values Dynamically In Textview - Android
I have a simple program with one button. Once I clicked on the button loop started and should display the current value in TextView dynamically. But this display the value when loo
Solution 1:
Try this:
inti=0; //declare this globallyfinalHandlerhandler=newHandler();
handler.postDelayed(newRunnable() {
@Overridepublicvoidrun() {
if(i != 10) {
text.append(" " + i);
i++;
handler.postDelayed(this, 1000);
}
}
}, 1000);
}
Make sure you declare int i = 0
globally
Solution 2:
Solution 3:
don't use Thread.sleep() in your main UI thread this should give an exception instead use a new Thread like this
ThreadmyThread=newThread(newRunnable() {
@Overridepublicvoidrun() {
for (int i=0;i<10;i++){
tv.setText("Value of I "+i);
Thread.sleep(500);
}
}
});
myThread.start();
or if there is more complex operations you make you will have to use AsyncTask calss
Post a Comment for "Display Values Dynamically In Textview - Android"