2013-10-08 54 views

回答

0

使用線程爲每秒生成隨機數。 使用此功能final Random rand = new Random();

0

對於「每秒」任務,您需要一個計劃的計時器。而對於「隨機值」部分,您可以使用「數學」包。那麼你可以這樣做:

final TextView textview = (TextView)findViewById(R.id.textview);   
TimerTask task = new TimerTask() { 

    @Override 
    public void run() { 
     textview.setText(Integer.toString(new Random().nextInt())); 

    } 
};  
Timer t = new Timer(); 
t.scheduleAtFixedRate(task, null, 1000L); 

這只是相當混亂。以此爲例,請勿複製/粘貼