Spinner听众从未触发过

时间:2014-01-22 20:46:00

标签: android android-fragments spinner listener android-spinner

我在一个片段中创建了一个微调器,并将一个聆听者与他联系起来。问题是永远不会调用onItemSelected。我在其中放了一条Log消息,但我看不到它。我在这里写了代码:

    /**
 * Metodo chiamato appena dopo che è stato istanziato il layout. Ottengo gli oggetti in esso presenti.
 * Method called just after the layout has been instantiated. I get the object that are there.
 * @param view Tutte le view nel layout.
 *             All the views that are in the layout.
 * @param savedInstanceState Se si creasse un punto di ripristino dell'activity quando si chiude.
 *                           If there has been created a reset point of the activity when it's closed.
 */
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);


    spnLinee = (Spinner) getView().findViewById(R.id.spinnerLinee);
    ArrayAdapter<String> adapter =new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,elementiSpinner);
    spnLinee.setAdapter(adapter);

    DownloadLinee l = new DownloadLinee();
    l.execute();

    spnLinee.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            Log.d("Linee", "onItemSelected qlks");
            lineaSelezionata = spnLinee.getSelectedItem().toString();
            Toast.makeText(context, lineaSelezionata, Toast.LENGTH_LONG).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            Log.d("Linee", "onNothingSelected qlks");
        }
    });
}

0 个答案:

没有答案