-1

i am new to android development. i'm making a simple app, which has one activity. In this activity i'm trying to loop for t<100 and printing value of t in text view. But the problem is that my app shows me white screen, till t==100. When t==100 it changes the value of textView to 100 and shows me the screen. Below is the code i'm using:

public class MainActivity extends AppCompatActivity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.AppTheme);
        setContentView(R.layout.activity_main);
        String inputFilePath = "/storage/emulated/0/1.jpg";
        for (int t = 0; t < 100; t++) {
            TextView tv = (TextView)findViewById(R.id.textView3);
            tv.setText("Welcome to android  "+t);

        }

    }
}

What i'm expecting is that i should see main activity view from start of app and should see content being changed of textView3 on screen

MNA
  • 287
  • 4
  • 14
  • Your expectations are wrong ... since you blocked UI thread there will be no screen update, which means no textview text update too ... obvious choice is to use different thread for iteration and post results back on UI thread ... fx with AsyncTask ... but it was asked so many times that I will not write more details – Selvin Apr 19 '17 at 12:40

2 Answers2

0

From your requirement i guess you need timer

int count;
     new CountDownTimer(10000, 100) {

         public void onTick(long millisUntilFinished) {
            count++;
            tv.setText("Welcome to android  "+ count);
         }

         public void onFinish() {

         }
      }.start();
Rama
  • 1,156
  • 1
  • 7
  • 13
-1

Your textview is displaying all the numbers but the for loop is executing so fast you are unable to see that.

The for loop executes within a few milliseconds . The human eye can see read more than 500 words a second. So all you are able to see is last number.

You need to add some waiting time between changing textview text. I suggest youto use this opportunity to and learn about text switcher

how to continuously switch textswitcher between two values every 2 seconds

Community
  • 1
  • 1
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
  • 1
    *Your textview is displaying all the numbers but the for loop is executing so fast you are unable to see that.* ... not true ... he wrote "Android App Shows White Screen Till the End Of Execution of All Code" ... *The for loop executes within a few milliseconds . The human eye can see read more than 500 words a second.* seriously? please learn what is an UI thread ... even if you would add `thread.sleep(1000)` insde the loop, you would not see the changes since **UI thread is blocked** – Selvin Apr 19 '17 at 12:53