Android – how to generate random numbers and display them on the screen?
Well, I'm quite new to Android, but I've managed to learn the basics by myself. I'm making an application. You press the button and a new screen opens. It displays a randomly generated number. The only problem is that I don't know how to generate and display random numbers. I've searched the Internet for many years and found only a small piece of information, which is really meaningful to me/
It would be great if someone could help me, or even just give me some information that should guide me in the right direction
Editor: (comments below)
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Random Number : " + Math.random());
int random = (int)Math.ceil(Math.random()*100);
setContentView(tv);
Most people agree with my code. What went wrong ^ ^ ^:/
resolvent:
Android's documentation is very good. This is an application for Hello World:
http://developer.android.com/guide/tutorials/hello-world.html
Just change
tv.setText("Hello, Android");
to
tv.setText("Random Number: " + Math.random());
And make sure to import the math library (if you are using eclipse, press Ctrl Shift o)