如何在 AsyncTask 的 doInBackground 期间实例化自定义 ArrayAdapter?
我有一个带有自定义数组适配器的列表视图。列表的每一行还有一个带有自己的适配器的画廊。所以一切正常。但快速滚动列表时,它会停滞,因为每一行都必须加载图库的第二个适配器。这只是毫秒,但您感觉很差,因为列表滚动不顺畅。所以我想在异步任务中加载图库的第二个数组适配器,以便滚动不受影响。但他们的问题是:
在 doInBackground 方法中我想这样做:
CustomAdapter customAdapter = new CustomAdapter(activity, R.layout.items, arraylist);
但他向我抛出了一个 futuretask 错误。我认为问题在于“活动”。我可以解决吗?还是他们没有机会?
我希望你能帮助我。
谢谢!
i have a listview with a custom arrayadapter. each row of the list have also a gallery with her own adapter. so everything works fine. but scrolling fast the list, it stagnates because each row must load the the secound adapter of the gallery. this are only millisecounds, but you feel ist, because the list don't scroll smooth. so i would like to load the secound arrayadapter of the gallery in an asynctask, so that the scrolling in not influence. but their is the problem:
in the doInBackground-method i want to do this:
CustomAdapter customAdapter = new CustomAdapter(activity, R.layout.items, arraylist);
but there he throws me a futuretask error. i thing it is the "activity" that is the problem. can i solve it? or is their no chance?
I hope you can help me.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您使用的是不可重用的 ListView 适配器。使用它们将提高应用程序速度,因为它将重用资源,并且您将避免垃圾收集。了解更多信息:http://www.softwarepassion.com /android-series-custom-listview-items-and-adapters/,特别是查看 OrderAdapter 实现。
您将无法修改 doInBackground 中的视图,因为它不是在 UI 线程上调用的。请参阅 Android 文档: http://developer.android.com/reference/android /os/AsyncTask.html
I think that the problem is that you are using non-reusable ListView adapters. Using them will improve application speed as it will reuse resources and you will avoid garbage collecting. Find out more at: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/, especially look at OrderAdapter implementation.
You won't be able to modify view in doInBackground as it is not invoked on the UI thread. Please refer to Android documentation: http://developer.android.com/reference/android/os/AsyncTask.html