我有一个 RSS 提要查看器,想向用户展示他们上次收听特定提要的时间。
这适用于列表中加载的第一个项目(在当前视图中可见的项目),但是当用户向下滚动列表视图时,lastViewedText
对于每个其他查看的提要都将隐藏。此外,当用户向上滚动到顶部(lastViewedText
之前成功显示的位置)时,lastViewedText
现在隐藏。BaseAdaptersgetView
方法是我设置可见性的地方。
自定义 BaseAdapter:
public class PodcastAdapter extends BaseAdapter{
private ArrayList<Podcast> feed;
private LayoutInflater inflater = null;
public PodcastAdapter(Activity a, ArrayList<Podcast> feed){
this.feed = feed;
inflater = (LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return feed.size();
}
public Object getItem(int position) {
return feed.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if(convertView == null)
vi = inflater.inflate(R.layout.rss_listview_item, null);
TextView title = (TextView)vi.findViewById(R.id.title);
TextView desc = (TextView)vi.findViewById(R.id.description);
TextView date = (TextView)vi.findViewById(R.id.date);
TextView lastViewedText = (TextView)vi.findViewById(R.id.lastViewedText);
Podcast feedIndex = feed.get(position);
title.setText(feedIndex.Title);
desc.setText(feedIndex.Description);
date.setText(feedIndex.Date);
lastViewedText.setText(feedIndex.LastViewedText);
if(feedIndex.LastViewedText.equals("")){
lastViewedText.setVisibility(View.GONE);
}
return vi;
}
}
为什么视图没有正确更新?标题、描述、日期都加载正确!