Q: TextView will not update from a loop in Android I have a simple app that updates a TextView from a values generated in a loop when i click on a button.
But when i run the app, it only shows the last number in the TextView. I added a Thread.sleep() to slow down the loop but it did not work, Still the same result. What am i doing wrong here? Thanks in advace
public class MainThread extends ActionBarActivity {
    Button btnShow;
    TextView txtSee;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_thread);

        btnShow = (Button) findViewById(R.id.btnShow);
        txtSee = (TextView) findViewById(R.id.txtSee);

        btnShow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    for (int i = 0; i <= 5; i++) {

                        String text1 = "Iteration No " + i + " occured";
                        txtSee.setText(text1);
                        Thread.sleep(2000);
                    }

                } catch (InterruptedException e) {
                }
            }
        });
    }

    ....
}


A: use 
 txtSee.append(text1);

instead of
 txtSee.setText(text1);

your loop is executing too fast to let you observe the changes

A: Call another function inside loop and use 
        txtSee.setText(text1); inside that function.
               or (int i = 0; i <= 5; i++) {

                            String text1 = "Iteration No " + i + " occured";
                            call_function(text1,txtSee);

                        }

call_function:-
call_function(String text1,TextView txtSee;){
                      txtSee.setText(text1);
                        Thread.sleep(2000);
                       }

