安卓:ViewHolder模式和不同类型的行? [英] Android: ViewHolder pattern and different types of rows?

查看:156
本文介绍了安卓:ViewHolder模式和不同类型的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ViewHolder模式改善的ListView滚动帧率,如下面的例子中看出: <一href="http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html">http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

是否可以同时使用不同种类的不同行意见,以保持这种模式?

在换句话说,是有可能做这样的事情:

 公开查看getView(INT的立场,观点来看,一个ViewGroup父){
     //计算的ViewID这里
     如果(查看== NULL || *的观点是不为空,但来自不同的XML创建比的ViewID *){
         鉴于= mInflater.inflate(的ViewID,NULL);
 

解决方案

是的,尽管它远不如覆盖 getViewTypeCount() getItemViewType ()在你的适配器。这会教Android的对象池只手,你行的正确类型背的 getView()

ViewHolder pattern improves ListView scrolling framerate, as seen in following example: http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

Is it possible to keep this pattern while using different kind of Views for different rows?

In other words, is it possible to do something like:

 public View getView(int position, View view, ViewGroup parent) {  
     // calculate viewID here
     if (view == null || *view is not null but was created from different XML than viewID* ) { 
         view = mInflater.inflate(viewId, null);  

解决方案

Yes, though it is far better to override getViewTypeCount() and getItemViewType() in your Adapter. That will teach Android's object pool to only hand you a row of the proper type back in getView().

这篇关于安卓:ViewHolder模式和不同类型的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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