Regarding android Development
I am doing an application in which I have to display the numbers on TextView randomly and automatically with the help of Timer. I am able to get the random Numbers in the log without repeating, but I am not able to print the same on device please help me...
Regards, Akki
Source:
//RandomNumber.java
public class RandomNumber extends Activity{
static Random randGen = new Random();
int tambolanum,count=0;
private Button previousbutton;
private Button startbutton;
private Button nextbutton;
int bingonum[]=new int[90];
boolean fill;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.numbers);
LinearLayout number=(LinearLayout)findViewById(R.id.numbersview);
final TextView randomnum=(TextView)findViewById(R.id.numberstext);
previousbutton=(Button)findViewById(R.id.previous);
nextbutton=(Button)findViewById(R.id.next);
startbutton=(Button)findViewById(R.id.start);
startbutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on click
//--- Initialize the array to the ints 0-90
do{
fill = true;
//Get new random number
tambolanum = randGen.nextInt(90) + 1;
//If the number exists in the array already, don't add it again
for(int i = 0; i < bingonum.length; i++)
{
if(bingonum == tambolanum)
{
fill = false;
}
}
//If the number didn't already exist, put it in the array and move
//To the next position
if(fill == true)
{
bingonum[count] = tambolanum;
count++;
}
} while(count < 90);
for(i=0;i
{
randomnum.setText(Integer.toString(bingonum[i]);
}
}
Asked by: Catherine846 | Posted: 25-01-2022
Answer 1
Answered by: Steven784 | Posted: 26-02-2022
Answer 2
The problem you're having is that you're overwriting your text in every itteration of this loop:
for(i=0;i
{
randomnum.setText(Integer.toString(bingonum[i]);
}
You need to build your string first then set it. Something like:
StringBuilder sb = new StringBuilder();
for(i=0;i /* where's the rest of this for-statement? */
{
sb.append(Integer.toString(bingonum[i]);
}
randomnum.setText(sb.toString());
Answered by: Carlos306 | Posted: 26-02-2022
Similar questions
Android Development Machine
With the latest SDK release, and the ability to download separate platforms releases into the SDK, the hardware resources required to develop for Android have increased significantly. Assuming that the developer targets all currently available seven platforms - that could take your dev machine to its knees. Taken alone the 'Android SDK Content Loader' takes nearly two minutes on a dual-core machine with 2GB memory.
How to set up android SDK for command line development on linux?
I'm trying to set up the android SDK to develop a simple program on the command line in Linux (Ubuntu 9.10). I tried eclipse, but it has know problems running on Ubuntu, so I gave up on it. Here's what I've done so far:
downloaded android-sdk_r05-linux_86.tgz from http://developer.android.com/sdk/index.html
tar xvzf androi...
nexus one - Device for Android development
Closed. This question is off-topic. It is not curre...
android - Setting up Droid for development
I am trying to follow the instructions on this page "Developing on a device". After I finished all the steps, and executes command "adb devices", my Droid is not listed. Is there anything else that I need to do if my device is Droid? It seems there are discussions on this issue but I could not find any definitive answer.
Android Development with Xcode
Closed. This question needs to be more focused. It ...
mobile phones - Android Development Device
Closed. This question does not meet Stack Overflow guid...
List of Open Source projects that aid Android app development
Flash or FlashLite development for Android?
I'm investigating the possibility to develop Flash or FlashLite apps that runs on Android as stand-alone apps, but I'm not finding anywhere a clear, definitive and up-to-date answer. Questions:
The HTC Hero supports Flash out-of-the-box (without installing it), right?...it's written everywhere, but which version? Flash 9? Flash 10? Flash Lite?
Does the Google Nexus One supports Flash, out-o...
What's a good, free source control system for eclipse android development?
Closed. This question does not meet Stack Overflow guid...
is there a masters degree in Mobile development like android?
Closed. This question is off-topic. It is not curre...
Android Development Machine
With the latest SDK release, and the ability to download separate platforms releases into the SDK, the hardware resources required to develop for Android have increased significantly. Assuming that the developer targets all currently available seven platforms - that could take your dev machine to its knees. Taken alone the 'Android SDK Content Loader' takes nearly two minutes on a dual-core machine with 2GB memory.
iphone - Best database for mobile phone development
Closed. This question does not meet Stack Overflow guid...
model view controller - Does Android UI development lend itself well to a particiular design pattern?
Does the Android platform lend itself well to a particular style of UI programming like MVC or MVP? Most of my UI experience is with spaghetti code on a very old embedded device or in GWT with MVP so I do not know where to start.
How to set up android SDK for command line development on linux?
I'm trying to set up the android SDK to develop a simple program on the command line in Linux (Ubuntu 9.10). I tried eclipse, but it has know problems running on Ubuntu, so I gave up on it. Here's what I've done so far:
downloaded android-sdk_r05-linux_86.tgz from http://developer.android.com/sdk/index.html
tar xvzf androi...
nexus one - Device for Android development
Closed. This question is off-topic. It is not curre...
What features for Android development are missing in Intellij9 compared to Eclipse?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android