0
@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View v = convertView;

        if(v == null){
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.country_row, null);
        }

        Country item = getItem(position);

        TextView tv1 = (TextView) v.findViewById(R.id.country);
        final CheckedTextView ctv = (CheckedTextView) v.findViewById(R.id.checked);
        ctv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ctv.toggle();
                Country country = (Country) listView.getItemAtPosition(position);
                Log.d("daim", country.getCountry() + " " + country.getCode());
                //listView.getCheckItemIds();
            }
        });

        tv1.setText(item.getCountry());

        return v;
    }

当我检查让我们说第一个元素(位置 0)时,它会被检查,但是当我向下滚动列表视图时,下一个“部分”的第一个位置也会被检查,这一直持续下去。例如,我有 100 个元素,我检查位置 0,然后检查位置 10、20、30、40 等。如何处理这种问题?

提前致谢。

4

1 回答 1

2

那是因为列表视图回收了它的视图,所以它保留了一个可重用的视图池。我通常使用的模式是:

if (this row need to be checked)
        check it
else
        force uncked it
于 2011-10-15T14:44:13.680 回答