Android - Saving state of dynamically changed layout

独自空忆成欢 提交于 2019-12-12 10:59:18

问题


I have a layout where users can add buttons and place them where they want. I want to allow the user to save their layout so that it is loaded the next time they open the app. Does anyone know if I can save the file on the sdcard? Alternatively I could use some kind of layout.getXml() method and put it in the database my app uses. Thanks in advance


回答1:


There is no file to save when you are generating a layout via code. You will have to create your own file format, which could be saved to the SD card or inserted into a database.




回答2:


You can us savedInstaceState() method with the same type object as parameter . there load the ui you want at the time of reloading. In onCreate() method put a condition whethere that savedInstaceState obj is null or not . if not then call the LoadUI().




回答3:


If I were you, I would create a class holding all the information about this layout and buttons. And write every information of the class to a file with JSONWriter. When the app has opened I just read the file and recreate the arrays using JSONObjects.



来源:https://stackoverflow.com/questions/5558487/android-saving-state-of-dynamically-changed-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!