我想創建一個showlist,並且正在使用的佈局必須取決於日期。getView位置變量奇怪的值
基本上,我只想在列表的開頭顯示一個項目的日期,或者如果該值不同於前一個項目的日期。
我存儲的日期作爲字符串數據成員(更容易在這種情況下)
,我十分奇怪的結果,所以我檢查了「位置」變量的值,以及由於某種原因後5左右,它會回到0並顯示一些隨機數字。我不知道這是爲什麼,也許有人可以幫助我?
這是我有:
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;
}