创建一个列表视图活动之前pre-创建行的看法? [英] pre-create row views before creating a listview activity?

查看:253
本文介绍了创建一个列表视图活动之前pre-创建行的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个标签的活动,并在每一个列表视图。我想使活动的加载和开放速度非常快。我很担心,既填充列表的标签将导致acivity打开时应用滞后。我是从我的数据库我的应用程序的启动画面时想加载数据和创建视图的数组,然后简单地把他们到列表视图一旦acivity启动。这是值得的?我似乎无法找到一个简单的方法做这样的事情。我假设我需要自定义的数组适配器。没有人有任何这样做somethng这样的经历吗?或者,你只是建议坚持中的onCreate()?

I have an activity that has two tabs and a list view in each. I want to make loading and opening of the activities very fast. I'm worried that populating both list tabs will cause the app to lag when that acivity opens. I'm thinking of loading data from my database during the splash screen of my app and creating an array of views, then simply throwing them onto the listviews once that acivity is launched. Is this worth the effort? I can't seem to find a simple way to do something like this. I'm assuming I will need custom array adapters. Does anyone have any experience doing somethng like this? Or would you just recommend sticking to the standard of using a cursor adapter in onCreate() ?

推荐答案

现在的问题是什么对于你需要加载他们那么快的原因。一般来说项目可以从数据库中真正快速读取。从来没有少,你应该这样做,在的AsyncTask 这样你就不会阻止这种操作的UI线程。

The question what's the reason for that you need to load them that fast. In general items can be read from a database really fast. Never the less you should do this in an AsyncTask so you won't block the UI thread with this operation.

还有一点就是,如果你想一个ListView中显示从数据库中的项目,你不应该一次读取所有的项目,并把它们放到绑定到列表中的数组。相反,你应该用你的数据库查询得到光标并将其绑定到一个 SimpleCursorAdapter 的CursorAdapter 你然后绑定到ListView。 CursorAdapters经过优化,能够在需要的时候从游标读取数据。请记住,创建对象是一个应该,如果没有必要避免对Android的一个昂贵的操作。所以,如果你列出一个真正的大,用户妥善不会整个列表滚动总是那么为什么preloading它的所有项目和创建的意见?

Another point is, if you want to display items from a database within a ListView you shouldn't read all the item at once and put them into an array that you bind to the list. Instead you should use the Cursor you got from the database query and bind it to a SimpleCursorAdapter or CursorAdapter which you then bind to the ListView. CursorAdapters are optimized to read data from a Cursor as they are needed. Remember that creating objects is an expensive operation on Android which should be avoided if unnecessary. So if your lists a really large and the user properly won't always scroll through the whole list then why preloading all items and creating views for it?

您当然可以prequery的启动画面中的数据库和存储返回游标的地方,直到你需要他们。

You can of course prequery the database during the splash screen and store the returned cursors somewhere until you need them.

不过,正如我在开始时说,我不知道你的应用程序做什么,所以很难说,如果它是值得努力与否。

But as I said at the beginning I don't know what your application does so it is hard to say if it is worth the effort or not.

这篇关于创建一个列表视图活动之前pre-创建行的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆