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
Dec 3rd, 2024
The travel industry is witnessing a significant transformation powered by artificial intelligence (AI). By integrating AI into various aspects of travel, companies can deliver seamless, personalised, and efficient services, ultimately […]
Read more
Nov 28th, 2024
The FemTech (Female Technology) industry has emerged as a transformative force, revolutionising women’s health and fitness through technology-driven solutions. With a global market value of $42 billion in 2020, FemTech […]
Read more
Oct 30th, 2024
Diwali is one of the biggest shopping and service seasons in India, where families prepare their homes, plan gatherings, and exchange gifts to celebrate the festival of lights. For businesses, […]
Read more