0
Fast text changing - Android Studio
I have a random number generator android app and I want to add a "computer thinking process" to it. I mean, I want to make the screen display fast changing random numbers for 5 seconds and then display the random number (after the "thought process"). I tried doing so, and it doesn't work: for(int i = 0; i < 50; i++){ try{ textView.setText(String.valueOf(random.randInt(1000))); Thread.sleep(100); // 0.1 sec } catch(IntrupttedException e){ } }
6 odpowiedzi
+ 2
And… did that work?
+ 2
When you animate something you could build in the calling of random.randint(1000) statement in the animation instead for loop and sleeping its thread.
+ 2
Plesse use web searching. Here we do not learn android studio:
https://youtu.be/jyg4uCTunRQ
0
JaScript , no... it says
"Skipped 60 frames! The application may be doing too much work on its main thread"
0
JaScript how can I do that ?
0
not sure if i get you right but try
private int i;
private Handler handler;
private Runnable runnable;
.
.
.
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
.
randomInit() ;
}
// this function starts draw
public void startDraw() {
handler.postDelayed(runnable, 0);
}
// this will initialize draw and after 50
// views of value ( after 5s) it will stop
public void randomInit() {
final Random r = new Random();
handler = new Handler();
i = 0;
runnable = new Runnable() {
public void run() {
textView.setText("" + r.nextInt(1000));
i++;
if(i == 50) handler.removeCallbacks(this);
else handler.postDelayed(this, 100);
}
};
}