2010-09-06 18 views

Répondre

0

J'utilise java.util.random.

Il s'agit essentiellement de java simple à ce stade. Vous pouvez utiliser java.util.nextInteger().

+1

Pour clarifier, c'est 'java.util.Random' et la méthode' nextInt() '. – CommonsWare

0

Est-ce que ce que vous cherchez?

Random r = new Random(); 
E element; 
int rand = r.nextInt(array.length); 
element = array[rand]; 
5

quelque chose comme ça dans votre onClickListener

Random rand = new Random(); 
int selector = rand.nextInt(yourList.length); 
yourList.get(selector); 

Quelque chose comme ça.

EDIT: En fait, si elle est un ArrayList alors il sera plus comme celui-ci

Random rand = new Random(); 
int selector = rand.nextInt(yourList.size()); 
yourList.get(selector);