I am reading a inputstream chunck by chunk and tryng to set read chunk to a textview from a Thread class but text is only getting printed after completion of while loop below is my code :
class SendFileThread extends Thread
{
Handler mHandler;
FileInputStream instream;
SendFileThread(Handler h, FileInputStream stream )
{
mHandler = h;
instream = stream;
this.setPriority(Thread.MAX_PRIORITY);
}
@Override
public void run()
{
final StringBuilder result = new StringBuilder();
Message msg;
byte [] usbdata = new byte[64];
int readcount = 0;
sendByteCount = 0;
int val = 0;
if(instream != null)
{
try
{
readcount = instream.read(usbdata,0,64);
}
catch (IOException e){e.printStackTrace();}
while(readcount > 0)
{
sendData(readcount, usbdata);
sendByteCount += readcount;
try
{
readcount = instream.read(usbdata,0,64);
if(readcount == -1){
pending = false;
//send_file = false;
setDefaultsBoo("pending",pending, J2xxHyperTerm.this);
}else{
result.append(new String(usbdata, 0, readcount));
}
runOnUiThread(new Runnable() {
@Override
public void run() {
readText.setMovementMethod(new ScrollingMovementMethod());
readText.setText(result.toString());
//scrollView.smoothScrollTo(0, readText.getHeight() + 30);
}
});
}
catch (IOException e){e.printStackTrace();}
}
}
}
}
text is getting set to textview only after all the work is done.