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
Mar 20th, 2025
In today’s fast-paced world, convenience is king. Whether it’s groceries, meals, or even medicines, Quick Commerce or Q-Commerce apps have revolutionised the way we shop and receive goods. These apps […]
Read more
Mar 18th, 2025
In the fast-paced world of technology, mobile apps have become an integral part of our daily lives. From ordering food to managing finances, apps are everywhere. But have you ever […]
Read more
Mar 13th, 2025
Singapore’s startup ecosystem is a beacon of innovation, consistently ranking among the top global hubs for technology and entrepreneurship. As of 2025, Singapore holds the 7th position worldwide, boasting an […]
Read more