I have an AutoCompleteTextView
which shows a dropdown which is automatically updated while typing text. If the text matches a specific String, a Spinner
control shows a certain category. This is done using a TextWatcher
. (I used both the methods onTextChanged(...)
and afterTextChanged(...)
. I have the same phenomenon with both methods.). This is working fine when entering the text manually. But this does not work when setting the text of the AutoCompleteTextView
using setText()
. The Text then comes from another activity that I started using startActivityForResult.
The value in the Spinner
control is not changed. If removing a letter and adding it again, the Spinner
control updates its value correctly. Does anyone know why? Does anyone know how to change this behavior?

- 467
- 9
- 25
2 Answers
one workaround could be to call explicitly afterTextChanged(...) on setText() of AutoCompleteTextView

- 658
- 6
- 7
-
the afterTextChanged is a method of the TextWatcher which is not accessible outside the TextWatcher. I cannot call it from outside. And even if I could, i would have to specify the text that was changed which does not make sense as the text is already entered in the TextView... – TomS Oct 11 '12 at 20:13
-
trie s smaller exemple with a simple textview. When the change is changed afterTextChanged is called even if the change is done via user input or settext method. I tested in my code and its working after this you could investigate what methods have you overwrite. – Adrian Herea Oct 11 '12 at 20:22
-
Ok, now I found out some more details: the value which is inserted into the TextView comes from another activity. It seems as if the SpinnerAdapter from my original activity does not contain any information after returning from the other Activity (the corresponding database cursor is still valid but the Adapter does not contain values anymore.) – TomS Oct 11 '12 at 22:10
I found out the solution:
after returning from my 2nd Activity I have to call requery()
on my adapter's cursor (((SimpleCursorAdapter)categorySpinnerAdapter).getCursor().requery();
). Maybe in the meantime, people would not call requery()
anymore because it's marked as deprecated, but I'll take care of that later...
(Can anyone explain this behavior? Is the cursor deactivated during onPause()
or onStop()
?)
But even that was not enough. My SpinnerControl
did not yet change its value.
I also have to call setAdapter()
on the SpinnerControl
to make it work again (spCategory.setAdapter(categorySpinnerAdapter);
).
(Does anybody know what's going on here? should both opening the Cursor (or requerying) and attaching the Adapter be done in onResume()
or onStart()
?)

- 467
- 9
- 25