我有一个Spinner
第一项是“选择一个”。在其中onTouchListener
,我已经从用于ArrayAdapter
. 现在我想Spinner
直接在监听器中打开他的菜单,而不需要用户的第二次触摸。
这是我创建微调器的地方:
spinnerCategoria = (Spinner) findViewById(R.id.spinnerCategoria);
spinnerCategoriaArray = new ArrayList<String>();
spinnerCategoriaArray=CpmAnalysisParams.categoria();
spinnerCategoriaArrayAdapter = new ArrayAdapter<String>(this, R.layout.spinner, spinnerCategoriaArray);
spinnerCategoriaArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCategoria.setAdapter(spinnerCategoriaArrayAdapter);
spinnerCategoria.setSelected(true);
spinnerCategoria.setOnTouchListener(Spinner_OnTouch);
spinnerCategoria.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Spinner spinnerOrdinata=(Spinner) findViewById(R.id.spinnerOrdinata);
if (arg0.getItemAtPosition(arg2).equals("Grafico a torta")){
spinnerOrdinata.setEnabled(false);
}
else{
spinnerOrdinata.setEnabled(true);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
这是他的ontouchlistener:
private View.OnTouchListener Spinner_OnTouch = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
spinnerCategoriaArrayAdapter=null;
Spinner spinnerCat=(Spinner)findViewById(R.id.spinnerCategoria);
spinnerCategoriaArray.remove(0);
spinnerCategoriaArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner, spinnerCategoriaArray);
spinnerCategoriaArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerCat.setAdapter(spinnerCategoriaArrayAdapter);
spinnerCat.setOnTouchListener(null);
}
return true;
}
};