简体   繁体   English

以编程方式创建持久性android视图

[英]Creating persistent android views programmatically

I have an application that can read some formatted data XML/JSON and builds views and listeners from this. 我有一个应用程序,可以读取一些格式化的数据XML / JSON并由此构建视图和侦听器。 Currently I am doing this in onCreate , but I don't want this to happen every time the app is opened, I'd rather do it only on first launch and the UI persisted or better still somehow do it when compiling/building the app from eclipse. 当前,我正在onCreate执行此操作,但我不希望每次打开应用程序时都发生这种情况,我宁愿仅在首次启动时执行,并且UI保持不变,或者最好还是在编译/构建应用程序时执行此操作从日食。

There are some ways you could do that. 有一些方法可以做到这一点。 You could try saving the data to a database and create views from this data whenever app opens and run a thread to download new data to database which refreshes view upon completing download. 您可以尝试将数据保存到数据库中,并在应用程序打开时尝试从该数据创建视图,并运行线程将新数据下载到数据库,该线程在完成下载后会刷新视图。 You could also give the option to update the data to user so he could update it as and when he wants it. 您还可以选择向用户更新数据,以便用户可以在需要时更新数据。

To use data only on compiling, it could be a big problem. 仅在编译时使用数据,这可能是一个大问题。 First of all, you would not be able to refresh the data any time! 首先,您将无法随时刷新数据! This data would make for a static app. 这些数据将构成一个静态应用程序。 If you still want to go forwards, you could either Hard code the in your code or write the data in a .txt file and read it from the file every time app opens! 如果您仍然想继续前进,则可以在代码中进行硬编码,也可以将数据写入.txt文件,并在每次打开应用程序时从文件中读取数据!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM