gpt4 book ai didi

java - Html.fromHtml() 在 ListView 回收问题中使用自定义 ImageGetter

转载 作者:行者123 更新时间:2023-11-30 02:23:34 25 4
gpt4 key购买 nike

我必须在 ListView 中显示一些带有来自 Internet 的图像的 HTML。图像在自定义 Html.ImageGetter 中处理。问题是,我需要可用的 TextView 来将图像下载到里面。这导致必须将 HTML 解析合并到 ArrayAdaptergetView 方法中。但是该方法在回收和重绘元素时经常被 Android 系统调用。

我怎样才能阻止这种回收发生?我假设我必须使用不同的流程。这是我当前的 getView() 方法:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = new TextView(context);
CharSequence element = getItem(position);
CharSequence html = Html.fromHtml(element.toString(), new MessageImageGetter(context, view), null);
view.setText(html);

view.setPadding(12, 4, 12, 4);

return view;
}

也许不使用 ListViewArrayAdapter 就可以实现类似列表的行为,它们不会经常回收和重绘。

最佳答案

How can I stop this recycling from happening?

你不知道。您创建了一个更丰富的模型对象。而不是看起来像 ListAdapter<String> 的东西, 有一个 ListAdapter<Thing> ,其中:

  • Thing保留您现有的字符串值 ( element )
  • Thing缓存 Html.fromHtml()结果
  • 你的 getView()得到 html CharSequence来自 Thing因此可以利用缓存

请随意替换比 Thing 更适用的名词, 当然... :-)

关于java - Html.fromHtml() 在 ListView 回收问题中使用自定义 ImageGetter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28129545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com