I have a list view of the emails of all the contacts in the phonebook.My list is a custom listview with a checkbox.Now the problem is as follows.

For eg i have 20 emails in the list.If i select the first email say "A" in the list and then scrolls the list,other emails are also getting selected by itself.Also if i again scroll back to the list ,my selected email "A" is being deselected by it own. I dnot know why this is occuring


public class EmailListAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<String> data;
    DbHandler dbHandler;

    public EmailListAdapter(Context context, ArrayList<String> data) {
        this.context = context;
        this.data = data;


    public int getCount() {
        return data.size();

    public Object getItem(int i) {
        return null;

    public long getItemId(int i) {
        return 0;

    public View getView(final int i, View view, ViewGroup viewGroup) {

        final ViewHolder holder;
        dbHandler = new DbHandler(context);

        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.email_custom_list, viewGroup, false);
            holder.tvContact = (TextView) view.findViewById(R.id.tv_email_name);
            holder.checkBox = (CheckBox) view.findViewById(R.id.cb_email_checkbox);

        } else {
            holder = (ViewHolder) view.getTag();

        holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (compoundButton == holder.checkBox) {
                    if (b) {
//                        dbHandler.updateContactList(data.get(i).getUserID(), 1);

                    } else {
//                        dbHandler.updateContactList(data.get(i).getUserID(), 0);


        return view;

    private class ViewHolder {
        TextView tvContact;
        CheckBox checkBox;


Related posts

Recent Viewed