I am making an app that sends and receives data and this data is displayed in one ListView
but I would like to change the color of the text so that the received texts (RX...) are colored and the texts (TX...) are of a different color, can this be done? What?.
Here is my code, I have tried to use Html.fromHtml
but it doesn't work.
//* Aqui Transmite datos
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = editText.getText().toString();
arrayList.add("TX: " + message);
//arrayList.add( Html.fromHtml( redB + "TX: " + message + colorEnd ) );
if (mTcpClient != null) {
mTcpClient.sendMessage(message);
}
mAdapter.notifyDataSetChanged();
editText.setText("");
}
});
.
.
//* Aqui Recibe datos
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
arrayList.add("RX: " + values[0]);
mAdapter.notifyDataSetChanged();
}
If reviewing a question you previously asked:
Two color text in TextView Android
you must add the html containers where the color is defined, when you add the values in the
ArrayList
for the "stream" texts:and for "receive" texts
When you add the texts in your
TextView
usesHtml.fromHtml()
:The solution to this is simple, you must create an adapter to which you enter itemns/components and not just text. To do this you must first create your layout (UI_component)
Then it only remains to add the adapter to your ListView