-3

How do I print integer values in a textview and also when I increasing the sleep time in the thread its not working correctly in android.

package com.example.chaljayar;   
import java.util.concurrent.Delayed;
import android.os.Bundle;   
import android.app.Activity;   
import android.view.Menu;  
import android.widget.TextView;

public class MainActivity extends Activity implements Runnable 

   {

       TextView Tv;
       int num = 0, i = 0;
       String con = "";

@Override
protected void onCreate(Bundle savedInstanceState)
  {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Tv = (TextView)findViewById(R.id.Text);
    Thread test = new Thread(this);
    test.start();
}
    @Override
    public void run() 
    {
        // TODO Auto-generated method stub
        while(i <= 100)
        {
            try{            
                    con += Integer.toString(i);
                    Tv.setText(con);
                    Thread.sleep(1000);
            } catch (Exception e)
            {
                // TODO: handle exception
                e.printStackTrace();
            }
            i++;
        }
    }   

}

kabuto178
  • 3,129
  • 3
  • 40
  • 61

1 Answers1

0

Try this To Thread alone and the other out of (try/catch) :

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }

If you want any thing about print int values in textview show this link please :

Integer value in TextView

Community
  • 1
  • 1
Oubaida AlQuraan
  • 1,706
  • 1
  • 18
  • 19