2010-01-26 52 views
0

我正在做一个应用程序,我必须在Timer的帮助下随机自动显示TextView上的数字。我能够获得在日志中的随机数不重复,但我不能打印相同的设备上,请帮我...关于android开发

问候, Akki

来源:

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

发布您的代码,所以我们可以看看 – 2010-01-26 07:28:05

回答

0
+0

我用同样的function..im能够在TextView的获得只有一个号码,但不是所有的数字.. :-(......我应该怎么做? – user259048 2010-01-26 07:24:13

0

您遇到的问题是,你在改写这个循环的每次itteration文本:

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

你需要先建立你的字符串然后设置它。喜欢的东西:

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