当我点击生成按钮时,我希望我的程序每 30 秒自动生成一次随机数,问题是如何在我的代码中执行此操作?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Random myRandom = new Random();
Button buttonGenerate = (Button)findViewById(R.id.generateme);
final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);
buttonGenerate.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
ArrayList<Object> Arry1 = new ArrayList<Object>();
for(int i=0;i<1;i++){
ArrayList<Integer> Arry = new ArrayList<Integer>();
for(int k=0;k<7;k++){
Arry.add(myRandom.nextInt(10));
}
Arry1.add(Arry);
}
textGenerateNumber.setText(String.valueOf(Arry1));
}
});
}
}