Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Multiple Textbox Java GUI
    text
    copied!<p>I have an activity or form in which there is one text box called time here. As suggested by experts from this forum I am using runnable to update the TextBox while receiving the data from wifi.</p> <p>My doubt is what to do when I want to update multiple TextBox's. Should I use multiple blocks of runnables like </p> <pre><code> time1.post(new Runnable() { @Override public void run() { time2.setText(s1); } }); time2.post(new Runnable() { @Override public void run() { time2.setText(s2); } }); time3.post(new Runnable() { @Override public void run() { time3.setText(s2); } }); </code></pre> <p>Or some other technique is there to update multiple TextBoxes? My present code is like below.</p> <pre><code>package com.example.cdttiming; public class MainActivity extends Activity { EditText time; String s; Button button; byte[] buffer = new byte[65535]; InetAddress ia = null; byte[] bmessage = new byte[1500]; DatagramPacket dp = new DatagramPacket(bmessage, bmessage.length); MulticastSocket ms = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); time = (EditText) findViewById(R.id.et_time); try { WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = wm.createMulticastLock("multicastLock"); multicastLock.setReferenceCounted(true); multicastLock.acquire(); ia = InetAddress.getByName("226.1.1.1"); try { ms = new MulticastSocket(4321); } catch (IOException e) { e.printStackTrace(); } try { ms.joinGroup(ia); } catch (IOException e) { e.printStackTrace(); } ms.setReuseAddress(true); } catch (UnknownHostException e) { time.setText(e.getMessage()); } catch (IOException e) { time.setText(e.getMessage()); } } public void startProgress(View view) { Runnable runnable = new Runnable() { @Override public void run() { while(true) { try { // String str="This is test string"; ms.receive(dp); s = new String(dp.getData(),0,dp.getLength()); char retval[] = s.toCharArray(); } catch (UnknownHostException e) { time.setText(e.getMessage()); } catch (IOException e) { time.setText(e.getMessage()); } ****////// My doubt is here if i have multple strings of data and multiple /// multiple textboxes to update then what to do ???**** time.post(new Runnable() { @Override public void run() { time.setText(s); } }); } // while } }; new Thread(runnable).start(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload