I'm new to the Android world, I'm doing an application-style Simon. but I'm stuck, I'm not able to create a code that creates random numbers to match the start button.
Could someone help me please?
thx
I'm new to the Android world, I'm doing an application-style Simon. but I'm stuck, I'm not able to create a code that creates random numbers to match the start button.
Could someone help me please?
thx
Try this. Returns an int in the half-open range (0 to 100)
Random rand = new Random();
int abcd = rand.nextInt(100);
Adding to Hemanth answer,
Random r = new Random();
int i1 = r.nextInt(45 - 28) + 28;
This gives a random integer between 28 (inclusive) and 45 (exclusive), one of 28,29,...,43,44.
I would generate a number from 1 to 4, to be inserted in the code part of the start button.
edit the code where I should add
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnStart= (Button)findViewById(R.id.status);
btnStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Here I should generate the random code
// I created the toast to see if it worked
Toast.makeText(MainActivity.this, " start click", Toast.LENGTH_LONG).show();
}
});