New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[分享]一种无需设置ViewHolder的ListView写法 #99
Comments
已收藏~ |
实现下!看看! |
我按照http://www.bignerdranch.com/blog/customizing-android-listview-rows-subclassing/ Logcat: @licheetec 能不能抽空看一下,因为实在太疑惑了。 |
@midiao 把你的代码发下。 |
Item.java
ItemAdapter.java
ItemView.java
MainActivity.java
activity_main.xml
item.view.xml
item.view.children.xml
@licheetec |
@midiao 看最后一个有原因的异常信息(Caused by的那个)
应该是填充xml初始化ItemView的时候,调用的是参数为 public ItemView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.item_view_children, this,
true);
setupChildren();
} 应该就可以了 |
按你说的修改之后,确实可以了,不过想问问
这两种构造方法有什么区别呢?(有三个参数的那个构造方法被我注释掉之后,程序依然可以运行;但是如果把两个参数的那个构造方法注释掉程序就会报错),这是为什么呢? |
受教了,非常感谢指导。 |
这种实现的原理是什么? |
@jorry 原理其实很简单,就是通过自定义View的方式,把ViewHolder的职能转移到该自定义View上,直接可以在自定义View中缓存子View的引用,而不用经过ViewHolder做中间人。 |
这个写法相当与把setTag的缓存 放到itemview 内存进行全局存储, 我不觉得这个效率比settag高 不过
上面这个是工具类
效率没有实测, 应该差不多, 取决与稀疏数组的查找 |
看这里,万能适配器:http://www.imooc.com/learn/372 |
http://www.bignerdranch.com/blog/customizing-android-listview-rows-subclassing/
The text was updated successfully, but these errors were encountered: