This routine read the data from a socket stream (ois). The question is why it works fine showing the read data through System.out.println(data) (used to debug) but it works wrong showing "null" in the EditText object of the android device when a data is received.
final EditText input_txt = (EditText) findViewById(R.id.input_txt);
.....
thrd = new Thread(new Runnable() {
public void run() {
while (!Thread.interrupted())
{
data = null;
try {
data = ois.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (data != null)
{
System.out.println(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
input_txt.setText(data+"");
}
});
}
}
}
});
thrd.start();
-
----- layout xml -------------------------------------
....
<EditText
android:id="@+id/input_txt"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:ems="10"
android:gravity="top" >
<requestFocus />
</EditText>