2010-01-26 7 views
0

Je fais une application dans laquelle je dois afficher les numéros sur TextView de manière aléatoire et automatiquement avec l'aide de Timer. Je suis en mesure d'obtenir les nombres aléatoires dans le journal sans répéter, mais je ne suis pas en mesure d'imprimer le même sur l'appareil s'il vous plaît aidez-moi ...En ce qui concerne android Développement

Cordialement, 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]); 
       } 
      } 
+2

Diffusez votre code afin que nous puissions jeter un oeil –

Répondre

0
+0

i utilisé la même function..im en mesure d'obtenir un seul numéro sur Textview mais pas tous les chiffres .. :-(... Que dois-je faire? – user259048

0

Le problème que vous rencontrez est que vous écrasez votre texte dans tous les itteration de cette boucle:

for(i=0;i 
{ 
    randomnum.setText(Integer.toString(bingonum[i]); 
} 

Vous devez d'abord créer votre chaîne, puis la définir. Quelque chose comme:

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