任何人都可以帮忙吗?我需要生成一个随机数,然后
public class MainActivity extends Activity implements OnClickListener {
TextView tv1;
Button bt1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button) findViewById(R.id.button1);
bt1.setOnClickListener(this);
tv1 =(TextView) findViewById(R.id.textView1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
Random r = new Random();
int i1=r.nextInt(80-65) + 65;
tv1 = (TextView) findViewById(R.id.textView1);
tv1.setText(i1);
break;};
}
}
然后它在按下按钮后关闭应用程序。