我的ListView自定義適配器與複選框行爲以奇怪的方式。當我檢查任何複選框並上下滾動,然後我的應用程序隨機檢查複選框。我很困惑。爲什麼此ListView自定義適配器與CheckBoxes行爲奇怪的方式?
這裏是getView功能
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewHolder holder;
if (convertView == null) {
convertView =inflater.inflate(R.layout.activity_main, parent,
false);
holder = new ViewHolder();
holder.checkBox = (CheckBox) convertView.findViewById(R.id.chkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.checkBox.setText(Name[position]);
return convertView;
}
ViewHoder.java類
public class ViewHolder {
CheckBox checkBox;
}
字符串中MainActivity.java類
String[] names=new String[]{
"Name1" , "Name2" , "Name3" ,"Name4" , "Name5" , "Name6","Name7" , "Name8" , "Name9","Name10" , "Name11" , "Name12"};