android - TextView remains the same it doesnt get set to any new value -


I am facing a problem, press on a button I try to read datainputstream in which the data is coming And displays data.

I am using loops for a while to read the data. But TextView does not have a dynamic update.

  TextView DatatxViewView = (TextView) PowerVibIID (RAD); DataInputStream Din = New DataInputStream (socket.getInputStream ()); Button getData = (button) findViewById (R.id.getdata); GetData.setOnClickListener (New OnClickListener) {public void onClick (see v) {//.......stuff ....... try {int buffer} size = 1024; byte [] buffer = new byte [Buffer size]; int bytesRead = -1; string message 1 = ""; while (true) {message1 = ""; data = din.redline (); bytesread = (reading). Length (); if (bytes read ! = -1) {Log.v (TAG, "data" + data); // I'm getting the data correctly / but it is not able to update it in textview :( DataActViewsettext (data); // Does not work}}    

You have to get out of your way and leave the control of the UI thread for your ideas to update. You should update your functionality to do so, So that you can not leave the UI thread.

Something like this:

  Public class Matskak Ascend Task & LT; Wide, String, Wide & gt; {Personal Final Textview Progress ; Public mitakes (text view progression) {this.progress = progress;} @ Override Precise eCite () at zero protected {progress.setText ("Starting ..."); } @ Override protected voice downline background (zero ... unused) {... including your buffer code, published progress (data); In your loop in the loop ...} @ Override protected Zero promotion update (string ... data) {progress.setText (data [0]); Progress.invalidate (); // Not sure if this is necessary or not protected protected at @OverridePostExecute {zero} {progress.setText ("Finish!"); }}   

Then you can execute it using your AsyncTask:

  New MyTask (datatextview) .execute (); Be sure to use  Edit  -  @ Override , which is not true if your method signature is correct Helps.   

Comments