Incidental observations (from a sedentary's perspective) on the crossroads of Open Source, Mobile Devices and E-Learning
Sunday, March 11, 2012
TextWatcher and change of device orientation
I encountered an interesting problem with a TextWatcher listening for changes in an EditText. The afterTextChanged method was called, each time, the device orientation changed. An answer on Stackoverflow let me understand what was happening: Android recreates the activity, and the automatic restoration of the state of the input fields, is happening after onCreate had finished, where the TextWatcher was added as a TextChangedListener. The solution to the problem consisted in adding the TextWatcher in onPostCreate, which is called after restoration has taken place. You can find the source in this commit of project MyExpenses on Github.
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDeleteWorked like a charm! Thanks
ReplyDeleteGreat! Thanks!!
ReplyDeletePlease update the Github link. Its dead. Please reply to this thread if done. thank you.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThe solution described in this blog post is no longer used in the referenced Github project, you fill find it on commit https://github.com/mtotschnig/MyExpenses/commit/bfad3088227583cf39c4def2264693fbc36457a9
ReplyDeleteThanks a lot!
ReplyDelete