Android ViewHolder模式
这个ViewHolder到底是什么呢?我们可以在官方sample看到这段代码 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html static class ViewHolder { TextView text; ImageView icon; } 可以看到它只是一个静态类,它的作用就在于减少不必要的调用findViewById 完整的官方例子,官方例子中convertView 也是避免inflating View。 然后把对底下的控件引用存在ViewHolder里面,再在View.setTag(holder)把它放在view里,下次就可以直接取了。 效率相差多少?看这篇文章:Android开发之ListView 适配器(Adapter)优化 /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may [...]