0

I'm using this block of code:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Cidade cidade = (Cidade) arg0.getSelectedItem();
                List<Bairro> bairros = RachandoTaxiController.getInstancia().getBairros(cidade);
                myAutoComplete = (AutoCompleteTextView) getView().findViewById(R.id.completeOrigem);
                myAutoComplete.addTextChangedListener(textWatcher);
                myAutoComplete.setAdapter(new ArrayAdapter<Bairro>(getActivity(), android.R.layout.simple_dropdown_item_1line, bairros));

            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });

There i have a Spinner and when i select an Item, i should set my AutoCompleteTextView (from holoeverywhere) based on user choice of Spinner. If i do it statically, it works. My autocompletetextview answer as expected. But when i put it into onItemSelected, my autocompletetextview still like edittext.... Nothing happens... How can i solve it?

Igor
  • 1,397
  • 3
  • 24
  • 56

1 Answers1

0

I think you should put

myAutoCompl = (AutoCompleteTextView) getView().findViewById(R.id.completeOrigem);
myAutoComplete.addTextChangedListener(textWatcher);

these lines outside of OnItemClickListener. Whenever you click on item, new instance of View from findViewById() is returned. Same for TextChangedListener. So try to put lines outside probably the best choice will be onCreate() method and it should works.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106