开发者

showing numbers on textview

What i m trying to do is, just showing numbers from 1 to 100 in a textview, randomly, and keep on changing until the view is active开发者_JAVA技巧.

But i am not able to continuously change random number when view is active.

it is just like a timer showing decrement from 10 to 0, but the only difference is i need to show random numbers in between 0 to 100.

How can show this on my view this is how i am trying to do something..may be a better approch will help me out

if (hasFocus) {
   try {  
      //Give the currentTimeMillis some time for the seed  
      Thread.sleep(2);  
   } catch (InterruptedException ex) {  
      ex.printStackTrace();  
   }  
   Random randomizer = new Random(System.currentTimeMillis());  
   // abcdef  = randomizer.nextInt(max-min+1)+min;
   return randomizer.nextInt(max-min+1)+min;  
} else { }


What do you mean with until the view is active? I am not sure how you are realizing this in your code, but could it be the case that you are actually writing the numbers into your view in a loop? In that case you are probably updating the UI to often which will lead to a crash or unwanted behavior. I'd suggest to put a delay between two different numbers. Maybe I misunderstood your question though. Some code showing what you are trying to do might be helpful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜