【发布时间】:2012-10-29 17:09:25
【问题描述】:
我有带有自定义光标适配器的列表视图。它包含数百个项目。向下滚动流畅且快速,但向后滚动 - 一直冻结。我不在 UI 线程上加载图像或某些操作。仅从光标中获取少量值并将其设置为 textviews
private class EpisodesAdapter extends CursorAdapter {
LayoutInflater inflater;
public EpisodesAdapter(Context context) {
super(context, null, false);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = inflater.inflate(R.layout.list_item_episode, parent, false);
view.setBackgroundResource(R.drawable.abs__list_selector_holo_light);
return view;
}
@Override
public void bindView(View view, final Context context, final Cursor cursor) {
final String title = cursor.getString(EpisodesQuery.EPISODE_TITLE);
final String episodeId = cursor.getString(EpisodesQuery.EPISODE_ID);
final String time = cursor.getString(EpisodesQuery.EPISODE_PUBLISHED_AT);
final String episodeUrl = cursor.getString(EpisodesQuery.EPISODE_URL);
final int stateId = cursor.getInt(EpisodesQuery.EPISODE_STATE_ID);
((TextView) view.findViewById(R.id.title)).setText(title);
......
}
}
一些想法可能导致此问题?
【问题讨论】:
-
如果应用程序完全冻结,可能会出现解释问题的 logcat 消息。你看到什么了吗?
-
您是否尝试过一般性能改进,例如视图持有者或异步任务加载器?
-
我认为您需要在使用后关闭游标。检查 logcat,它可能会显示一些有关其冻结原因的信息
-
1. logcat 中的唯一消息是光标窗口:窗口已满,但我在向下滚动时也看到了它,并且运行顺畅 2. 是的,我试过了。我只从游标加载数据。在 cursoradapter 中不使用 Viewholder,因为它有自己的 getview 实现来处理它。 Newview 只被调用了几次,并且对每一行都调用了 bindview。 3. 在哪里关闭光标?光标适配器处理它,我无法在 bindview 中关闭它我不知道可能是什么问题,因为向下滚动整个列表很好,但是一旦我到达末尾并尝试向上滚动它就会冻结。这很奇怪。
标签: android android-layout android-cursoradapter android-scroll