마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

RecyclerView 중복 데이터 제거 방법 여쭤봅니다. [closed]

0 추천

RecyclerView를 이용해 이미지 리스트를 만들었는데요. 화면에 출력되는 데이터가 제대로 나오지 않아 질문 드립니다.

예를들어 0 ~ 25까지의 이미지를 출력하는데 

0

1

2

3

4

5

6

7

8

9

10

7     <-------------이전에 출력된 데이터가 나옵니다. 11번 이미지가 나오지 않고 건너뛰어 버립니다.

12

13

일단 ArrayList를 로그로 찍어본 결과 중복된 데이터는 없는 것을 확인했습니다.

어답터에서 뿌려줄때 문제인거 같은데 잘 모르겠습니다.

아래는 어답터 소스 입니다.

public class StoryListAdapter extends RecyclerView.Adapter<StoryListAdapter.StoryListViewHolder> {

        PringDatabaseHelper dbHelper;
        private List<Story> categories;
        ArrayList<String> storyPhotoArrayList;

        private Context mContext;

        public class StoryListViewHolder extends RecyclerView.ViewHolder {

            protected TextView vName;
            protected ImageView vImage;
            protected TextView vDate;
            protected TextView vCount;
            protected TextView cou;

            public StoryListViewHolder(View itemView) {
                super(itemView);

                vImage = (ImageView) itemView.findViewById(R.id.photo);
                vName = (TextView) itemView.findViewById(R.id.txtStoryTitle);
                vDate = (TextView) itemView.findViewById(R.id.txtDate);
                vCount = (TextView) itemView.findViewById(R.id.txtCount);
                cou = (TextView) itemView.findViewById(R.id.cou); // 임시 카운터

            }
        }

        public StoryListAdapter(Context mContext, List<Story> categories) {
            this.mContext = mContext;
            this.categories = categories;
        }

        @Override
        public int getItemCount() {
            return categories.size();
        }

        @Override
        public StoryListViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

            View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_storylist_layout_item, viewGroup, false);
            StoryListViewHolder viewHolder = new StoryListViewHolder(itemView);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(final StoryListViewHolder storyListViewHolder, int i) {

            final Story story = categories.get(i);
            int currentItemCountView = currentItemCount(story.getID());

            Log.d(TAG, "+++++++++++++++++++++++++++++" + String.valueOf(i));

            try {
                Picasso.with(mContext)
                        .load(Uri.parse(story.getURI()))
                        .resize(600, 600)
                        .centerCrop()
                        .into(storyListViewHolder.vImage);

                storyListViewHolder.vName.setText(story.getCATEGORY_NAME());
                storyListViewHolder.vDate.setText(story.getCREATE_DATE());
                storyListViewHolder.vCount.setText(" · " + String.valueOf(currentItemCountView) + "개의 사진");

                storyListViewHolder.cou.setText(String.valueOf(i));

            } catch (Exception e) {

            }

            storyListViewHolder.vImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Intent intent = new Intent(mContext, StoryDetailViewActivity.class);
                    intent.putExtra(PhotoDetailViewActivity.EXTRA_IMAGE, story.getID());
                    mContext.startActivity(intent);

                    Toast.makeText(storyListViewHolder.vName.getContext(), story.getCATEGORY_NAME() + " 선택됨.", Toast.LENGTH_SHORT).show();
                }
            });

        }

        public int currentItemCount(int position) {
            dbHelper = new PringDatabaseHelper(getActivity());
            storyPhotoArrayList = dbHelper.selectStoryPhotoString(position);
            int extraCurrentItemCount = storyPhotoArrayList.size();
            return extraCurrentItemCount;
        }
    }

뷰홀더를 생성할 때 이미 생성된 것인지 아닌지를 판별하거나 잘못된 데이터를 정상 데이터로 교체할 수 있는 방법 없을까요?

 

 

질문을 종료한 이유: xml에서 cardview 코드가 잘못되어 있었습니다.
dexx (140 포인트) 님이 2015년 10월 12일 질문
dexx님이 2015년 10월 14일 closed
...