在android中多次调用Getview [英] Getview Called multiple times in android

查看:27
本文介绍了在android中多次调用Getview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究单元格的重用,目前我正在使用适配器的 getview 方法,我遇到一个问题,即我的 getview 方法调用了 9 次,但在应用程序启动时它应该只调用 5 次,因为我只显示 5行.

I am working on reuse of cell and currently i am working in getview method of adapter and i got one problem that my getview method called 9 times but it should call only 5 times at the starting of app because i am displaying only 5 rows.

public View getView(int position, View view, ViewGroup viewgroup) 
{   
    ViewHolder holder=null;

    if(view==null)
      {  
               view = inflater.inflate(R.layout.my_row_layout, viewgroup, false);
              Log.d("Testing","View is nuLL");
                holder.thumbnils  = (ImageView)view.findViewById(R.id.Thumbnils);
                     holder.hover =(ImageButton)view.findViewById(R.id.hover);
                    holder.title  =(TextView)view.findViewById(R.id.title);
                    holder.hoveroverlay  =(ImageView)view.findViewById(R.id.hoveroverlay);
               }view.setTag(holder);
             }
         else
    {
        Log.d("Testing","view is not null");

        holder = (ViewHolder) view.getTag();
       }

          return view;
      }

          @Override
public int getCount() {
    // TODO Auto-generated method stub

    if(data.size()%NumberOfCell==0)
    {
        //return Number rows in listview 
        return data.size() /NumberOfCell;

    }
    else
    {
        //If total number of videos are ODD than display one row extra for remaining videos
        return data.size() /NumberOfCell+1;
    }

}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 1;
}

    Here is my xml

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/imageView2"
    android:layout_alignLeft="@+id/linearLayout1"
    android:layout_below="@+id/linearLayout1"
    android:scrollbars="none"
     android:divider="#000000" 
      android:dividerHeight="2dp"
     >
</ListView>
  </RelativeLayout>

请帮帮我谢谢…………

推荐答案

让你的listview高度等于fill_parent,然后再试一次..

Make your listview height equal to fill_parent and try it again..

这篇关于在android中多次调用Getview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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