October 29th, 2011, 12:44 PM
|
#3 (permalink)
|
|
New Member
Join Date: Oct 2011
Location: England
Posts: 4
Device(s): Asus Transformer, HTC Legend
Thanks: 0
Thanked 0 Times in 0 Posts
|
I'm not sure if it is possible, but really there isn't any need to. The following code will do exactly what you ask:
Code:
//aspinner is a global Spinner. Doesn't have to be, just so you can access it in the onTouch call
aspinner = (Spinner) findViewById(R.id.spin);
String[] params = new String[]{"SelectA","SelectB","SelectC"};
ArrayAdapter<String> adapter2 =
new ArrayAdapter<String> (this,
android.R.layout.simple_spinner_dropdown_item,params);
aspinner.setAdapter(adapter2);
//IMPORTANT: This is onTouch and NOT onItemSelected
aspinner.setOnTouchListener((new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Randomly select between 0-2
Random r = new Random();
aspinner.setSelection(r.nextInt()%3);
return true; //returning true will prevent the options popping up
}
}));
|
|
|