Android : Take input from user and then compare with random value

on Monday, September 22, 2014



public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final TextView tv=(TextView) findViewById(R.id.textView1);
Button b=(Button) findViewById(R.id.button1);

final Random dice=new Random();
final Random random=new Random();

b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
tv.setText(String.valueOf(dice.nextInt(10)+"+"+String.valueOf(random.nextInt(10)))+"= ?");
}
});
}
}

0 comments:

Post a Comment