Hi im trying to set the value of a textview with .setText in a method that is run by a thread but it is being appended to the TextView instead. The parameter String f is a being send to the method in a for loop like this:
for (int j = 0; j < 5; j++) {
String[] string = array[j].split(":");
String y= string[0];
String x= string[1];
determineSeat(y, something, x);
}
}
private void determineSeat(String is, String cs, String f)
{
TextView txtHand = null;
String txt = null;
if (iSeat < cSeat) {
x = cSeat - iSeat;
if (x == 1) {
txtHand = (TextView) findViewById(R.id.txtHand8);
txt = txtHand.getText().toString();
txtHand.setText("");
txtHand.setText(txt + ":" + f);
}
}
XML:
<TextView
android:id="@+id/txtHand1"
android:layout_width="73dp"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:text=" " />
I want it to be cleared everytime i put something in the textview instead of being appended anyone knows what the problem is?
You are setting it to
"txt + ":" + f"."txt"is defined as whatever was already in the textview. If you just want to have it set to"f"every time the method is called, do"txtHand.setText(f);"As is, you are asking it to take whatever is currently in the textview, and add a colon and"f."