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){ } }

12th Oct 2021, 2:16 PM
Yahel
Yahel - avatar
6 ответов
+ 2
And… did that work?
12th Oct 2021, 2:33 PM
JaScript
JaScript - avatar
+ 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.
12th Oct 2021, 2:43 PM
JaScript
JaScript - avatar
+ 2
Plesse use web searching. Here we do not learn android studio: https://youtu.be/jyg4uCTunRQ
12th Oct 2021, 3:18 PM
JaScript
JaScript - avatar
0
JaScript , no... it says "Skipped 60 frames! The application may be doing too much work on its main thread"
12th Oct 2021, 2:35 PM
Yahel
Yahel - avatar
0
JaScript how can I do that ?
12th Oct 2021, 2:52 PM
Yahel
Yahel - avatar
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); } }; }
12th Oct 2021, 8:17 PM
Jimmy Phoitick
Jimmy Phoitick - avatar