For-loop inside a For-loop - ListArrays - Android, Java! -


this noob question have ask anyway because think i'll go crazy soon.

what want achieve listview populates twitter , have implemented, 2 listarrays gets populated tweet , picture url. successful, when refresh twitter new pile of twitter gets below old ones.

i clear listarrays twitter disappears in list not desirable, want add new tweets, , make new tweets on top of list.

so guess 2 fold question

  1. how make list add not there?, and
  2. how make latest tweet appear on top?

could use great input, code below essential part of (messy) code, refresh method.

public void updatetwitter(){          twitter = new twitterfactory().getinstance();          try {             queryresult result = twitter.search(new query(tweetquery));             tweets = result.gettweets();             (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 search tweets: " + te.getmessage());         }     } 

presumably, lazyadapter derives baseadapter , backed urlarray. if so, have tweets appear on top, need add them beginning of array.

use add(0, newentry) add beginning of array , notifydatasetchanged() tell adapter post updates.

a couple of other notes:

1) unclear me intend, seeing code twww.equals(twwwwwww). seems you're maintaining old tweets , trying add new ones, unclear variable names twww, twwwwww, , tweetstring, can guess.

2) shouldn't have keep setting adapter. once relationship between listview, adapter, , backing array set, should have update array , notify adapter.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -