The getView() method of the class extending the BaseAdapter holds the state of the currently displayed view which is invalidated when scrolling the listview. So, in order to avoid this problem, proceed in the following manner.
• Create a nested class within the class (class which is extending BaseAdapter Class), namely, Viewholder.
• Declare all the views of an individual list item in this Viewholder Class.
• Create an object of this Viewholder class in the getView() method and initialize all the views declared in the Viewholder class using this object.
Example :
Activity activity;
publicclassViewHolder{
TextViewtextview;
CheckBoxcheckbox;
}
public View getView(finalint position, View convertView, ViewGroup parent)
{
View vi=convertView;
LayoutInflaterinflater = activity.getLayoutInflater();
vi = inflater.inflate (R.layout.listitem, null);
ViewHolder item=newViewHolder();
item.textview = (TextView)vi.findViewById(R.id.textview1);
item.checkbox = (CheckBox)vi.findViewById(R.id.checkbox1);
vi.setTag(item);
return vi;
}
Implement this and check the state of the checkbox while scrolling the listview.
Find us on Google+
Related Posts...
Mobile AppsTechnologies
Oct 13th, 2026
Singapore’s tropical climate can change quickly, with bright sunshine giving way to sudden showers, thunderstorms, or heavy rainfall. For residents, commuters, tourists, and businesses, reliable weather information can make everyday […]
Read more
Sep 29th, 2026
Mobile applications have become an essential investment for businesses in Singapore looking to improve customer engagement, streamline operations, and expand their digital presence. From startups launching their first product to […]
Read more
Sep 24th, 2026
India’s grocery shopping landscape is rapidly becoming more digital, creating opportunities for startups to build convenient and scalable grocery delivery platforms. Consumers increasingly expect to discover products, compare prices, place […]
Read more