i am beginer to android,i would like to print 1 -10 numbers in order like one by one as shown follows
1
2
3
4
5
6
7
8
9
10
i would like to print those numbers like 1 3secs after 2, 3secs after 3,3secs after 4……so on
i have written code as follows to print 1-10 but it displaying only 10 .
@Override
public void onClick(View v) {
name=((TextView)findViewById(R.id.textView1));
for(int i=0;i<11;i++){
name.setText("hai"+i);
}
please is there any solutions for that?
This does not work, like this, as
onClick()is run on the UI thread, blocking it for updates until youronClick()returns. WhileYou can solve that with an
AsyncTask, where thedoInBackground()method is doing the loop,sending the number to print via
publishProgress()and haveonProgressUpdate()update the TextView.Here is an example of the usage of
AsyncTask. Also have a look at the docs which also illustrates progress updates.