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