朋友,
我使用以下自定义适配器为android listview 调用notifydatasetchanged();
后,我面临的问题是错误的位置第一次将数据绑定到列表位置时工作完美但在我调用notifydatasetchanged()之后; 我得到位置参数错误
请指导我在做任何帮助时会遇到什么错误。
public EfficientAdapter(Context context,List<DalCategories> value) {
mInflater = LayoutInflater.from(context);
obj = value;
}
public View getView(final int position, View convertView,
final ViewGroup parent) {
ViewHolder holder;
if(convertView == null)
{
convertView = mInflater.inflate(R.layout.list_category_item, null);
holder = new ViewHolder();
holder.TextTitle = (TextView) convertView.findViewById(R.id.list_item_title);
holder.checkBoxes = (CheckBox) convertView.findViewById(R.id.chkSubCategory);
convertView.setTag(holder);
}else
{
holder = (ViewHolder)convertView.getTag();
}
// while setting checkbox state after notify datasetchanged i get wrong position
if(obj.get(position).isIs_Selected())
{
holder.checkBoxes.setChecked(true);
}
holder.checkBoxes
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton buttonView, boolean isChecked) {
if(obj.get(position).isIs_Any() && isChecked)
{
if( adapter != null)
{
adapter.notifyDataSetChanged();
}
}
}
});
holder.TextTitle.setText(obj.get(position).getTitle());
return convertView;
}
class ViewHolder
{
public TextView TextTitle;
public CheckBox checkBoxes;
}
@Override
public Filter getFilter() {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getCount() {
return obj.size();
}
@Override
public Object getItem(int position) {
return obj.get(position);
}
}
答案 0 :(得分:1)
我也在努力集成这个适配器,但我注意到你的持有者类缺少static关键字。每次你给持有人打电话,可能都不是你的想法。