How to generate a random number in android? In my activity , it has one button
, textView
and editText
. The user firstly need to type an alphabet between A-D. When button is clicked, it will display an alphabet. The alphabet should not same with the input.
The alphabet will then deleted from the list.
Assume the list is {A,B,C,D} If user type A, the system will display any alphabet except A. Let said the output is B, then B will deleted from the list. So if the button clicked again, it will not display B again.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Random r = new Random();
input=(EditText)findViewById(R.id.editText);
a=input.getText().toString();
btnNext = (Button) findViewById(R.id.button);
Name=(TextView)findViewById(R.id.textView);
btnNext.setOnClickListener(new View.OnClickListener() { //if next button is clicked
@Override
public void onClick(View v) {
if(a=="A")
{
//what should write here ?
}
Name.setText(Integer.toString(r.nextInt(100) + 1));
}
});
}
This is what I've tried, but it is used to generate a random number. Any hints ? Thanks
Aucun commentaire:
Enregistrer un commentaire