Prevent spinner dropdown to show
hm... try to use setClickable(fasle)
or setEnabled(false)
if only one item in spinner
.
Try this
public class SpinnerActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
List<String> list = new ArrayList<String>();
list.add("list 1");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
if (list.size() < 2) {
spinner.setClickable(false);
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Toast.makeText(SpinnerActivity.this, "Catch it!", Toast.LENGTH_SHORT).show();
}
return true;
}
});
}
}
}
To prevent spinner from showing drop-down list, I only return true in onTouch(...), like this:
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
});