如何滚动列表时,停在自定义列表视图复选框自动检查?列表、自定义、停在、视图

2023-09-04 04:29:20 作者:藝術家

我制作具有checkbox.The问题的自定义列表视图是,当我滚动列表视图,它不检查成为检查automatically.This的项目是$ C $词现在用:

I am making a custom listview having a checkbox.The problem is that when i scroll the list view,the items which are not checked become checked automatically.This is the code i am using:

public class ContactAdapterSetRule extends ArrayAdapter<String> {

public static ArrayList<String> s_itemsOfAdapterArrayList;
Context m_context;
public static ArrayList<String> s_checkedIds = new ArrayList<String>();

public ContactAdapterSetRule(Context context, int textViewResourceId, ArrayList<String> s_contactNameArrayListSplash) {
    super(context, textViewResourceId, s_contactNameArrayListSplash);
    this.s_itemsOfAdapterArrayList = s_contactNameArrayListSplash;
    this.m_context = context;
    s_checkedIds.clear();  //Clearing the list of Checked Ids
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View l_view = convertView;
    if (l_view == null) 
    {
        LayoutInflater l_vi = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        l_view = l_vi.inflate(R.layout.showthecontacts, null);

        ViewHolder viewHolder = new ViewHolder();
        viewHolder.l_nameCheckBox = (CheckBox) l_view.findViewById(R.id.checkBox);;

        l_view.setTag(viewHolder);
    }


    String l_nameOfContact = s_itemsOfAdapterArrayList.get(position);
    ViewHolder holder = (ViewHolder) l_view.getTag();

    if (l_nameOfContact != null)
    {
        if (holder.l_nameCheckBox != null) 
        {
            holder.l_nameCheckBox.setText(l_nameOfContact);
        }

        holder.l_nameCheckBox.setOnClickListener(new OnItemClickListener(position,holder.l_nameCheckBox.getText(),holder.l_nameCheckBox));          
    }
    return l_view;
}

private class ViewHolder
{
    CheckBox l_nameCheckBox;
}

private class OnItemClickListener implements OnClickListener
{           
    private int l_positionOfItemClicked;
    private CharSequence l_text;
    private CheckBox l_checkBox;
    OnItemClickListener(int position, CharSequence text,CheckBox checkBox)
    {
        this.l_positionOfItemClicked = position;
        this.l_text = text;
        this.l_checkBox = checkBox;
    }
    @Override
    public void onClick(View arg0) 
    {
        if(l_checkBox.isChecked())
        {
            Log.v("","Checkbox is checked");
            for(int i = 0;i < s_checkedIds.size();i++)
                Log.v("",s_checkedIds.get(i));

            if(!s_checkedIds.contains(l_text.toString()))
            {
                s_checkedIds.add( l_text.toString());
                Log.e("",l_text.toString()+" is added to s_checkedIds");
            }
        }
        else
        {
            Log.v("","Checkbox is Unchecked");

            for(int i = 0;i < s_checkedIds.size();i++)
                Log.v("",s_checkedIds.get(i));
            if(s_checkedIds.contains(l_text.toString()))
            {
                s_checkedIds.remove( l_text.toString());
                Log.e("",l_text.toString()+" is removed from s_checkedIds");
            }
        }  
    }

请帮助我。我很没有得到有关如何执行it.Thanks事先的任何想法。

Please help me.I am not getting any idea about how to do it.Thanks in advance.

推荐答案

的这链接帮助我解决我的问题。

This link helped me to solve my issue..

编码快乐:)