我正在重用单元格,目前我正在使用适配器的 getview 方法,我遇到了一个问题,我的 getview 方法调用了 9 次,但它应该在应用程序开始时只调用 5 次,因为我只显示 5 行。
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>
请各位大侠帮帮我谢谢。。。。。。