Suppose we have an array of 100 Strings, which you get them from R.string.xml.
private String lapi[]={"R.string.lapi0", "R.string.lapi1", "R.string.lapi2", "R.string.lapi3"..."R.string.lapi99};
Also we have a TextView and a Button:
lapicera=(TextView)findViewById(R.id.lapicera);
btnElegir=(Button)findViewById(R.id.btnElegir);
and we want that when we click the button get us a random value between 0 and 100:
int random=(int) Math.round(Math.random()*100);
The problem: what would be the easiest way to edit the TextView with the array value to which the random value belongs ?. For example if the value which returns random is 40, what I want to do is this:
pelicula.setText(getResources().getString(lapi[random]));
That is the most effective solution I thought, but doesn't work.
Do you know if there are other similar work as this way ?, without having to use a switch.
Sorry if my english isn't clear.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire