安卓:实现ViewHolder [英] Android: Implementing ViewHolder

查看:160
本文介绍了安卓:实现ViewHolder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Andr​​oid应用程序来实现ViewHolder,但我不断收到这ViewHolder不能被解析为一个类型,没有对进口的任何建议。任何人都知道如何解决这个问题?

I am trying to implement ViewHolder in my Android app, but I keep getting that ViewHolder cannot be resolved to a type, without any suggestions for an import. Anyone know how to get around this?

推荐答案

这是因为 ViewHolder 不是一类就是的的是Android SDK,你自己做的。 根据我所能<一个href="http://xjaphx.word$p$pss.com/2011/06/16/viewholder-pattern-caching-view-efficiently/">find,一个 ViewHolder 是存储视图(每行一个ListView通常情况下)的较大面积的实现,所以它是一种辅助类和高速缓存机制。这是一款例如我发现在Android开发者有什么 ViewHolder 将包含。

That's because a ViewHolder is not a class that is from the Android SDK, you make it yourself. Based on what I can find, a ViewHolder is an implementation that stores Views (per row in a ListView usually) for a larger area, so it is a sort of helper class and cache mechanism. This is one example I found on Android Developers of what a ViewHolder would contain.

static class ViewHolder {
  TextView text;
  TextView timestamp;
  ImageView icon;
  ProgressBar progress;
  int position;
}

然后你可以在实现它 ListAdapter 或同级。

这篇关于安卓:实现ViewHolder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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