I’m trying to crate a showlist, and the layout that is being used has to depend on the date.
Basically, I only want to show the date of an item at the beginning of the list or if the value is different than the date of the previous item.
I’m storing the date as a String datamember (easier in this case)
I’m getting quite strange results, so I checked out the value of the ‘position’ variable, and for some reason after 5 or so, it goes back to 0 and show some random numbers. I have no idea why this is, so maybe someone could help me?
This is what I have:
private LayoutInflater li = LayoutInflater.from(this.getContext());
private String currentDate;
public EpisodeListAdapter(){
super(UnwatchedEpisodesActivity.this, 0, episodeList);
currentDate = episodeList.get(0).getAirDate().getRawDateString();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d(AppConstants.APP_NAME, "pos:" + position);
if(position == 0){
Log.e(AppConstants.APP_NAME, "A");
if(convertView == null){
convertView = li.inflate(R.layout.episode_date, parent, false);
}
((TextView) convertView.findViewById(R.id.date1)).setText(episodeList.get(position).getAirDate().getRawDateString());
((TextView) convertView.findViewById(R.id.text3)).setText(episodeList.get(position).getTitle());
((TextView) convertView.findViewById(R.id.text4)).setText(episodeList.get(position).getShowName());
}
else if(currentDate != episodeList.get(position).getAirDate().getRawDateString()){
Log.e(AppConstants.APP_NAME, "B");
if(convertView == null){
convertView = li.inflate(R.layout.episode_date, parent, false);
}
((TextView) convertView.findViewById(R.id.date1)).setText(episodeList.get(position).getAirDate().getRawDateString());
((TextView) convertView.findViewById(R.id.text3)).setText(episodeList.get(position).getTitle());
((TextView) convertView.findViewById(R.id.text4)).setText(episodeList.get(position).getShowName());
currentDate = episodeList.get(position).getAirDate().getRawDateString();
}
else {
Log.e(AppConstants.APP_NAME, "C");
if(convertView == null){
convertView = li.inflate(R.layout.episode_row, parent, false);
}
((TextView) convertView.findViewById(R.id.text1)).setText(episodeList.get(position).getTitle());
((TextView) convertView.findViewById(R.id.text2)).setText(episodeList.get(position).getShowName());
currentDate = episodeList.get(position).getAirDate().getRawDateString();
}
return convertView;
}
Try to inflate view every time. If anyone have a better solution, please, provide.
private LayoutInflater li = LayoutInflater.from(this.getContext());