1

I've a Spinner whose first item is "Select one". In its onTouchListener I've eliminated the first item from the array used for the ArrayAdapter. Now I want the Spinner to open his menu directly inside listener without a second touch from users.

This is where I create 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
    }
});

This is his 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;
    }
};
4

0 に答える 0