Am still learning B4A and so far, it’s a fascinating language, very intuitive and fun. Thanks to Erel and the whole team. I have realized when working with my app, if the layout has an edittext view with content already keyed, when I change the phone orientation, the edittext clears all the content and I have to enter text again, how do I change this to avoid losing entered content on an Edittext view?
Am still learning B4A and so far, it’s a fascinating language, very intuitive and fun. Thanks to Erel and the whole team. I have realized when working with my app, if the layout has an edittext view with content already keyed, when I change the phone orientation, the edittext clears all the content and I have to enter text again, how do I change this to avoid losing entered content on an Edittext view?
Some tips:
- The Activity is re-created when the orientation changes; all views are re-initialised
- Have a look at the Android activity lifecycle and at @Erel 's additional comments
- As @FrostCodes mentioned, you could save and restore the data; the StateManager class used to be useful, but as @Erel added to that thread: this is old code; use B4XPages + KVS2 instead
- Use B4Xpages (it makes things a lot easier); the orientation is normally locked in a B4XPages app, but search the forum for 'B4XPages orientation' and some potentially interesting threads will appear
- B4XPages also makes it a lot easier to write cross-platform code
Thanks all for your information, saving and restoring data from a global variable could help if maybe I had 1 edittext with data, but if I have several edittext boxes for data entry, it makes the code long with variables. So their is currently no fix for this with B4A, let me try and reduce the number of edittext views to save on variables that may confuse me. Anyway, am grateful for your valuable assistance.
Thanks all for your information, saving and restoring data from a global variable could help if maybe I had 1 edittext with data, but if I have several edittext boxes for data entry, it makes the code long with variables. So their is currently no fix for this with B4A, let me try and reduce the number of edittext views to save on variables that may confuse me. Anyway, am grateful for your valuable assistance.
It's not an issue with B4A it's to do with Android itself. You can iterate through all controls to make saving easier or better still, switch to B4XPages.
[Edit] If you insist on using activities you can use State Manager to make the transition between orientations easy.
I may be asking a "tree behind the forest " kind of question here but, are you using b4pages? Isn't b4pages supposed to manage that and many other scenarios that would otherwise need in fact the saving upon pause and read on resume?