问题
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