tags:

views:

96

answers:

5

Hi guys,

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]);
                } 
            }
A: 

setText(CharSequence text)

Silvio Donnini
i used the same function..im able to get only one number on Textview but not all numbers.. :-( ...what should i do?
A: 

used the same function..im able to get only one number on Textview but not all numbers.. :-( ...what should i do?

you should post your code.
JRL
A: 

//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);

I moved the source up into the question. Please delete this answer. Also, it looks like there's some missing code.
fiXedd
A: 
I moved the source up into the question. Please delete this answer. Also, it looks like there's some missing code.
fiXedd
A: 

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());
fiXedd