I think you are misunderstanding something very important. Java Strings are immutable that means that you can't change them.
"How do I, somehow, change the text in the string?"
You can't. The text in the string cannot be changed. It is immutable. Any "solution" that involves changing the text in a String WON'T WORK in Java. (Got that?)
When you do this:
output.setText(outputString);
outputString = "";
the assignment does not change the value that is displayed in the text field. It just changes the String that the local variable outputString
refers to.
And when you do this:
output.setText("");
output.setText(outputString);
it does not cause outputString
to change. It just changes the displayed text to nothing and then immediately changes it to whatever outputString
currently refers to.
If you want to change the value displayed in the text field to nothing, you JUST do this:
output.setText("");
Perhaps the other thing that you've got wrong in your thinking is that you think that this:
output.setText(outputString);
sets up a relationship between the text field output
and the variable outputString
... such that when the user types into the field, the outputString
variable is magically updated. That is NOT so. In fact, it CANNOT be so, because you cannot pass the address of variable.
In fact, output.setText(outputString);
just passes the value of outputString
to the text box object. If and when the user types something into the box, the characters are stored somewhere else, and only returned to your code ... as a new String ... when your code calls output.getText()
.