在滚动

时间:2016-10-23 07:06:15

标签: android listview

每当我向下滚动时,它会向我显示重复值。我使用setTag()方法来避免重复值,但仍然存在重复值。请提供帮助。我添加了我的Adapter类,如下所示:

CustomAdapter.java

@Override
    public int getCount() {
        return searchVedBeanList.size();
    }

    @Override
    public Object getItem(int position) {

        if (searchVedBeanList != null && searchVedBeanList.size() != 0 && searchVedBeanList.size() > position) {
            return searchVedBeanList.get(position);
        } else {
            return null;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("deprecation")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        final VedBean vedBean = (VedBean) getItem(position);

        if (convertView == null) {
                LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                holder = new ViewHolder();

                convertView = li.inflate(R.layout.search_ved_list_item, parent, false);

                holder.mantraSansTextView = (TextView) convertView.findViewById(R.id.mantraSansTextView);
                holder.vedTextView = (TextView) convertView.findViewById(R.id.vedTextView);
                holder.commentratorTextView = (TextView) convertView.findViewById(R.id.commentratorTextView);
                holder.rishiDevtaLinearLayout = (LinearLayout) convertView.findViewById(R.id.rishiDevtaLinearLayout);
                holder.rishiTextView = (TextView) convertView.findViewById(R.id.rishiTextView);
                holder.devtaTextView = (TextView) convertView.findViewById(R.id.devtaTextView);
                // initialize Atharvaved components
                holder.atharvavedVedLinearLayoutSearch = (LinearLayout) convertView.findViewById(R.id.atharvavedVedLinearLayoutSearch);
                holder.kandTextViewAtharvaSearch = (TextView) convertView.findViewById(R.id.kandTextViewAtharvaSearch);
                holder.suktaTextViewAtharvaSearch = (TextView) convertView.findViewById(R.id.suktaTextViewAtharvaSearch);
                holder.mantraNumTextViewAtharvaSearch = (TextView) convertView.findViewById(R.id.mantraNumTextViewAtharvaSearch);
                // initialize Yajurved components
                holder.yajurVedLinearLayoutSearch = (LinearLayout) convertView.findViewById(R.id.yajurVedLinearLayoutSearch);
                holder.adhyayTextViewYajurSearch = (TextView) convertView.findViewById(R.id.adhyayTextViewYajurSearch);
                holder.mantraNumTextViewYajurSearch = (TextView) convertView.findViewById(R.id.mantraNumTextViewYajurSearch);
                // initialize Samved components
                holder.samVedLinearLayoutSearch = (LinearLayout) convertView.findViewById(R.id.samVedLinearLayoutSearch);
                holder.archikTextViewSamSearch = (TextView) convertView.findViewById(R.id.archikTextViewSamSearch);
                holder.adhyayTextViewSamSearch = (TextView) convertView.findViewById(R.id.adhyayTextViewSamSearch);
                holder.dashatiTextViewSamSearch = (TextView) convertView.findViewById(R.id.dashatiTextViewSamSearch);
                holder.mantraNumTextViewSamSearch = (TextView) convertView.findViewById(R.id.mantraNumTextViewSamSearch);
                // initialize Rigved components
                holder.rigVedLinearLayoutSearch = (LinearLayout) convertView.findViewById(R.id.rigVedLinearLayoutSearch);
                holder.mandalTextViewRigSearch = (TextView) convertView.findViewById(R.id.mandalTextViewRigSearch);
                holder.suktaTextViewRigSearch = (TextView) convertView.findViewById(R.id.suktaTextViewRigSearch);
                holder.mantraNumTextViewRigSearch = (TextView) convertView.findViewById(R.id.mantraNumTextViewRigSearch);

                convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();
        }
        char charArr[] = vedBean.getMantraSans().toCharArray();
        for (int i = 0; i < charArr.length; i++) {
            holder.mantraSansTextView.setText(holder.mantraSansTextView.getText().toString() + charArr[i]);
        }
        String vedStr = "<b>"+UtilityConstant.STR_VED+" : "+"</b>"+UtilityConstant.getVedValueFromId(vedBean.getVedId());
        holder.vedTextView.setText(Html.fromHtml(vedStr));
        String commentatorStr = "<b>"+UtilityConstant.STR_COMMENTATOR+" : "+"</b>"+UtilityConstant.getCommentratorValueFromId(vedBean.getCommentratorId());
        holder.commentratorTextView.setText(Html.fromHtml(commentatorStr));
        holder.rishiTextView.setVisibility(View.GONE);
        return convertView;
    }

0 个答案:

没有答案