我正在为 listview 的每个 Iten 实现带有 listview 的复选框。我遇到的问题是,当我单击任何单个复选框时,其他一些未单击的复选框也被随机单击。
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
final int as=position;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.grid_item, null);
holder = new ViewHolder();
holder.textheader = (TextView) vi.findViewById(R.id.item1);
holder.textcpu = (TextView) vi.findViewById(R.id.item2);
holder.text_modified_date = (TextView) vi.findViewById(R.id.item4);
holder.text_cpu = (TextView) vi.findViewById(R.id.item3);
holder.text_checkbox=(CheckBox)vi.findViewById(R.id.checkBox1);
vi.setTag(holder);
holder.text_checkbox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (holder.text_checkbox.isClickable()) {
itemChecked.set(as, true);
packages=as;
} else if (!holder.text_checkbox.isClickable()) {
itemChecked.set(as, false);
}
String packag=app_package.get(as);
Log.d("package listttttttttt", packag);
}
});
} else {
holder = (ViewHolder) vi.getTag();
}