java - UI not updated from onProgressUpdate -
i writing following code:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_test); start(); } public void start() { scrollview device= (scrollview) findviewbyid(r.id.test); device.removeallviews(); tablelayout devicetable = new tablelayout(getapplicationcontext()); devicetable.setid(951357); device.addview(devicetable); devicelist = new arraylist<deviceinformation>(); wifimanager wifi = (wifimanager)getsystemservice( context.wifi_service ); if(wifi != null) { wifimanager.multicastlock lock = wifi.createmulticastlock("wifidevices"); lock.acquire(); } wifiinfo winfo = wifi.getconnectioninfo(); mac = winfo.getmacaddress(); sendmulticastflyport = new thread(new flyportsender(mac)); sendmulticastflyport.start(); sendmulticastcomputer = new thread(new computersender(mac)); sendmulticastcomputer.start(); sendmulticastraspberrypi = new thread(new raspberrysender(mac)); sendmulticastraspberrypi.start(); new devicesearcher().execute(); } private class devicesearcher extends asynctask<void, deviceinformation ,void> { @override protected void onpreexecute() { super.onpreexecute(); tablelayout devicetable = (tablelayout) findviewbyid(951357); tablerow tr = new tablerow(getapplicationcontext()); layoutparams layout = new layoutparams(layoutparams.match_parent, layoutparams.wrap_content); tr.setlayoutparams(layout); textview tv = new textview(getapplicationcontext()); tv.settext("searching"); tv.settextcolor(color.black); tv.setvisibility(1); tr.addview(tv); devicetable.addview(tr); } @override protected void doinbackground(void... arg0) { publishprogress((deviceinformation)null); new thread() { public void run() { multicastsocket socketcomputer=null; try { socketcomputer = new multicastsocket(wificonstants.computer_recv_port); socketcomputer.joingroup(inetaddress.getbyname(wificonstants.computer_network_addr)); socketcomputer.setsotimeout(1*20*1000); byte[] inbufcomputer = new byte[1024]; datagrampacket inpacketcomputer = new datagrampacket(inbufcomputer, inbufcomputer.length); while(true) { system.out.println("listening..."); socketcomputer.receive(inpacketcomputer); system.out.println("received"); string msg = new string(inbufcomputer, 0, inpacketcomputer.getlength()); deviceinformation device = new deviceinformation(1, msg, inpacketcomputer.getaddress().tostring()); publishprogress(device); log.v("received:","received computer :" + inpacketcomputer.getaddress() + " msg : " + msg); //system.out.write(inpacket.getdata(),0,inpacket.getlength()); system.out.println(); thread.sleep(2000); } } catch(exception e) { log.v("exception:","during receiving computer: "+e.tostring()); publishprogress((deviceinformation)null); } { socketcomputer.close(); } } }.start(); new thread() { public void run() { multicastsocket socketraspberry=null; try { socketraspberry = new multicastsocket(wificonstants.raspberry_recv_port); socketraspberry.joingroup(inetaddress.getbyname(wificonstants.raspberry_network_addr)); socketraspberry.setsotimeout(1*20*1000); byte[] inbufraspberry = new byte[1024]; datagrampacket inpacketraspberry = new datagrampacket(inbufraspberry, inbufraspberry.length); while(true) { system.out.println("listening..."); socketraspberry.receive(inpacketraspberry); system.out.println("received"); string msg = new string(inbufraspberry, 0, inpacketraspberry.getlength()); deviceinformation device = new deviceinformation(2, msg, inpacketraspberry.getaddress().tostring()); publishprogress(device); log.v("received:","received raspberry :" + inpacketraspberry.getaddress() + " msg : " + msg); //system.out.write(inpacket.getdata(),0,inpacket.getlength()); system.out.println(); thread.sleep(1500); } } catch(exception e) { log.v("exception:","during receiving raspberry: "+e.tostring()); publishprogress((deviceinformation)null); } { socketraspberry.close(); } } }.start(); } @override protected void onprogressupdate(deviceinformation... d) { super.onprogressupdate(d[0]); layoutparams layout = new layoutparams(layoutparams.match_parent, layoutparams.wrap_content); tablelayout devicetable = (tablelayout) findviewbyid(951357); if(check==false) { check=true; log.v("enter","removing views"); system.out.println(devicetable); //devicetable.removeallviews(); } deviceinformation device = d[0]; if(device!=null) { devicelist.add(device); tablerow tr = new tablerow(getapplicationcontext()); checkbox check = new checkbox(getapplicationcontext()); check.settext(device.getdevicetypestring()+"\n"+device.getipaddress()); check.setvisibility(1); check.setid(14569+rowcounter); check.settextcolor(color.white); if(rowcounter%2==0) { tr.setbackgroundcolor(color.dkgray); } else { tr.setbackgroundcolor(color.gray); } check.setpadding(70, 0, 0, 0); check.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { checkbox checksee = (checkbox) findviewbyid(view.getid()); } }); switch(device.getdevicetype()) { case 1: check.setbuttondrawable(r.drawable.pcx); break; case 2: check.setbuttondrawable(r.drawable.raspberryx); break; case 3: check.setbuttondrawable(r.drawable.flyportx); break; } check.setenabled(true); check.setchecked(false); check.setlayoutparams(layout); tr.addview(check); tr.setlayoutparams(layout); tr.setvisibility(1); devicetable.addview(tr); rowcounter++; } else { if(deviceendcounter==3) { tablerow tr = new tablerow(getapplicationcontext()); textview tv = new textview(getapplicationcontext()); tv.settext("no devices found"); tv.setvisibility(1); tv.setlayoutparams(layout); tv.settextcolor(color.white); tr.setbackgroundcolor(color.black); tr.setvisibility(1); tr.setlayoutparams(layout); tr.addview(tv); system.out.println(devicetable); devicetable.addview(tr); } else { deviceendcounter++; } } } }
the above code reaches onprogressupdate
method. , access ui views not make change ui.
but if want remove view being removed. not adding view.
i dont know do.? have tried every possible ways.
edit:
i tried print ui tablelayout
using system.out.println();
05-13 11:33:04.936: v/exception:(16280): during receiving computer: java.net.sockettimeoutexception 05-13 11:33:04.946: v/exception:(16280): during receiving raspberry: java.net.sockettimeoutexception 05-13 11:33:04.946: i/system.out(16280): android.widget.tablelayout@40dc32a8 05-13 11:33:04.956: v/exception:(16280): during receiving flyport: java.net.sockettimeoutexception 05-13 11:33:04.976: v/exception:(16280): during receiving computer: java.net.sockettimeoutexception 05-13 11:33:04.976: v/exception:(16280): during receiving raspberry: java.net.sockettimeoutexception 05-13 11:33:04.986: v/exception:(16280): during receiving flyport: java.net.sockettimeoutexception 05-13 11:33:05.016: i/system.out(16280): android.widget.tablelayout@40dc32a8
this logcat
.
apart this, 3 threads running dont know how getting timeoutexception
more once per thread
.
in above, using
layoutparams layout = new layoutparams(layoutparams.match_parent, layoutparams.wrap_content); textview tv = new textview(getapplicationcontext()); tv.setlayoutparams(layout);
whereas should not contain:
tv.setlayoutparams(layout);
Comments
Post a Comment