如何滚动列表时,停在自定义列表视图复选框自动检查? [英] How to stop automatic checking of checkboxes in custom listview when scrolling the list?
本文介绍了如何滚动列表时,停在自定义列表视图复选框自动检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作具有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..
编码快乐:)
这篇关于如何滚动列表时,停在自定义列表视图复选框自动检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文