Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

Getview Called multiple times in android

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>

Please help me guys Thank you.........

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...