我的列表視圖的數據越來越重複滾動,雖然我的點擊工作正常,我知道這是關於setTag或定位的問題,但我無法修復它...所以我需要一點幫助,從你們列表中的數據越來越重複滾動
這裏是適配器我getView功能: -
@Override
\t public View getView(final int position, View convertView, ViewGroup parent) {
\t \t final ViewHolder viewHolder;
\t \t final int i = position;
\t \t final WholeProductList listItem = mProductList.get(position);
\t \t if (convertView == null) {
\t \t \t convertView = mLayoutInflater.inflate(
\t \t \t \t \t R.layout.list_comapare_product, parent, false);
\t \t \t viewHolder = new ViewHolder();
\t \t \t viewHolder.tvProductName = (TextView) convertView
\t \t \t \t \t .findViewById(R.id.tv_product_name);
\t \t \t viewHolder.tvProductName.setText(mProductList.get(position)
\t \t \t \t \t .getName());
\t \t \t viewHolder.imgProduct = (ImageView) convertView
\t \t \t \t \t .findViewById(R.id.img_product);
\t \t \t viewHolder.imgadd = (ImageView) convertView
\t \t \t \t \t .findViewById(R.id.img_plus);
\t \t \t viewHolder.mRlConatiner = (RelativeLayout) convertView
\t \t \t \t \t .findViewById(R.id.rl_container);
\t \t \t convertView.setTag(viewHolder);
\t \t } else {
\t \t \t viewHolder = (ViewHolder) convertView.getTag();
\t \t }
\t \t viewHolder.mRlConatiner.setTag(position);
\t \t viewHolder.mRlConatiner.setOnClickListener(new OnClickListener() {
\t \t \t @SuppressWarnings("static-access")
\t \t \t @Override
\t \t \t public void onClick(View v) {
\t \t \t \t if (tickedItems.contains((Integer) v.getTag())) {
\t \t \t \t \t // Already ticked, set to plus
\t \t \t \t \t viewHolder.imgadd.setImageDrawable(activity.getResources()
\t \t \t \t \t \t \t .getDrawable(R.drawable.plus));
\t \t \t \t \t tickedItems.remove((Integer) v.getTag());
\t \t \t \t \t if (((AppController) activity.getApplicationContext()).cartItemList
\t \t \t \t \t \t \t .contains(listItem)) {
\t \t \t \t \t \t ((AppController) activity.getApplicationContext()).cartItemList
\t \t \t \t \t \t \t \t .remove(listItem);
\t \t \t \t \t }
\t \t \t \t } else {
\t \t \t \t \t tickedItems.add((Integer) v.getTag());
\t \t \t \t \t viewHolder.imgadd.setImageDrawable(activity.getResources()
\t \t \t \t \t \t \t .getDrawable(R.drawable.tick));
\t \t \t \t \t if (!((AppController) activity.getApplicationContext()).cartItemList
\t \t \t \t \t \t \t .contains(listItem)) {
\t \t \t \t \t \t ((AppController) activity.getApplicationContext()).cartItemList
\t \t \t \t \t \t \t \t .add(listItem);
\t \t \t \t \t }
\t \t \t \t }
\t \t \t \t Session.getmCountImage().setvisibilityOn();
\t \t \t }
\t \t });
\t \t if (tickedItems.contains(position))
\t \t \t viewHolder.imgadd.setImageDrawable(activity.getResources()
\t \t \t \t \t .getDrawable(R.drawable.tick));
\t \t else
\t \t \t viewHolder.imgadd.setImageDrawable(activity.getResources()
\t \t \t \t \t .getDrawable(R.drawable.plus));
\t \t return convertView;
\t }
感謝