This is a noob question but I have to ask it anyway because I think I'll go crazy soon.
What I want to achieve is a ListView that populates by twitter and this I have implemented, the two ListArrays gets populated by the tweet and the picture URL.
This is successful, but when I refresh twitter the new pile of twitter gets below the old ones.
I could simply clear the ListArrays but then all the twitter disappears in the list which is not desirable, I simply want to add only the new tweets, and make the new tweets get on top of the list.
So I guess this is a two fold question
- How do I make the list only to add which is not there?, and
- How do I make the latest tweet appear on top?
Could really use some great input, the code below is the most essential part of the (messy) code, which is the refresh method.
public void updateTwitter(){
twitter = new TwitterFactory().getInstance();
try {
QueryResult result = twitter.search(new Query(TWEETQUERY));
tweets = result.getTweets();
for (Tweet tweet : tweets) {
String tweetProfile = tweet.getProfileImageUrl();
String twwwwww = tweet.getText();
for(String tww : tweetString){
if(tww.equals(twwwwww)){
System.out.println("Not added");
} else {
tweetString.add(twwwwww);
urlArray.add(tweetProfile);
}
}
}
if(adapter != null) {
tweetList.setAdapter(adapter);
System.out.println("adapter sets, not created");
} else {
adapter = new LazyAdapter(this, urlArray, tweetString);
tweetList.setAdapter(adapter);
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
}
}