【问题标题】:Listview scrolling up freezingListview向上滚动冻结
【发布时间】: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


【解决方案1】:

我想我明白了。游标中的一列包含一些 blob 数据。当我从查询选择中删除此列时,它平滑地向上滚动。谢谢大家的回答。

【讨论】:

    【解决方案2】:

    ListView empty if SimpleCursorAdapter closed()。此链接可能会回答关闭光标的位置。如果它向下滚动顺利,我看不出向上滚动时冻结的原因。我很好奇你面临的问题。

    【讨论】:

    • 光标适配器不需要查看器。 newview 和 bindview 已经处理好了。正如我告诉。向下滚动很流畅,只有当我尝试向上滚动时它才会开始冻结。
    猜你喜欢
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2017-06-14
    相关资源
    最近更新 更多