android - Updating ListView:ArrayAdapter in a timer -


i new android not programming. have long years of embedded linux experience. findin strange simple tasks updating listview on timer, not able find documentation , source interleaved in pelothra of classes find strange spend 2-3 days googling basic thing updating list in timer. how hard can be, bad luck not able find single sample that..... please help.

what trying simple, writing activity has timer, timer reads status value http , displays in list.

first created listview attached arrayadapter 0 elements in that. in timer doing following

//timer run code public void run() {     strng = getstatus()              adapter.add(strng);     adapter.notifydatasetchanged(); } 

but not @ working.

can please me sample.... or @ google please put samples of basic things.

thanks

i managed running though, here small code. please have modify play it. creating blog shortly put these samples....

now working basic extent, if modify (a) how hard / easy replace string @ particular position in adapter. right using arrayadapter not have replace function. why :( ? (b) if have create service , let service update string values[]. way ? read intents service , activity in same app, cant there global data ? (c) , point java/android, why write function definition new call. isn't hard debug , incorrect way code ?

public class screenone extends activity { protected listview mylist; protected arraylist<string> strlist; protected arrayadapter<string> adapter; protected timertask ttask; protected int ctr =0; protected timer timer;  protected string[] values = new string[] { "xyandroid", "iphone", "windowsmobile",         "blackberry", "webos", "ubuntu", "windows7", "max os x",         "linux", "os/2", "ubuntu", "windows7", "max os x", "linux",         "os/2", "ubuntu", "windows7", "max os x", "linux", "os/2",         "android", "iphone", "windowsmobile" }; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_screen_one);      mylist = (listview) findviewbyid(r.id.s1listview);     strlist = new arraylist<string>();      adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, strlist);      mylist.setadapter(adapter);       timer t = new timer();     //set schedule function , rate     t.scheduleatfixedrate(             new timertask()              {                  @override                 public void run()                 {                     runonuithread(                             new runnable() {                                  @override                                 public void run() {                                      if(ctr  < values.length) {                                         adapter.add(values[ctr]);                                         ctr++;                                      }                                 }                             });                  }             }             ,             0,             500); } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -