我认为你正在清除数据
this.tweets.clear();
this.users.clear();
..
我认为,由于推文和用户都具有相同的引用(从活动传递到适配器),因此推文和两个用户(在适配器和活动上都指向相同的 ArrayList),因此两者都很清楚,因此这些行没有意义,因为两者是空的
this.tweets.addAll(tweets);
this.users.putAll(users);
try
public TweetAdapter(Context context, ArrayList<Tweet> tweets, HashMap<String, User> users) {
mInflater = LayoutInflater.from(context);
this.tweets = new ArrayList<Tweet>();
this.users = new HashMap<String, User>();
this.tweets.addAll(tweets);
this.users.putAll(users);
Collections.sort(this.tweets, new TweetTimeComparator());
}
..
public void refresh(ArrayList<Tweet> tweets, HashMap<String, User> users) {
this.tweets.clear();
this.users.clear();
this.tweets.addAll(tweets);
this.users.putAll(users);
Collections.sort(this.tweets, new TweetTimeComparator());
notifyDataSetChanged();
}
但请注意:现在对两条推文(在适配器上和在活动上)和两个用户(在适配器上和活动上)的引用是不同的。
任何其他使用 this.tweets.addAll(tweets); 的地方都不应该有直接的赋值,如adapter.tweets = Activity.tweets;