【发布时间】:2013-12-17 12:38:23
【问题描述】:
您如何控制获得的随机数。例如,您将如何控制数字 10 - 20 的随机数生成器。我正在使用 eclipse,这是我的代码:
public class FrontPage extends Activity {
Random rndNumbers = new Random();
int d20 = rndNumbers.nextInt(20) +1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
Button add = (Button) findViewById(R.id.button1);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int d20 = rndNumbers.nextInt(20) +1;
EditText comment = (EditText) findViewById(R.id.editText1);
Editable commy = comment.getText() ;
String str = commy.toString();
TextView TV = (TextView) findViewById(R.id.textView1);
TV.setText("" + str + d20);
TV.setTextSize(d20);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.front_page, menu);
return true;
}
}
请帮忙。
【问题讨论】:
标签: java android eclipse random textview