which gets a Text with setText.. But I want to Reset the value again later.
The results I could find on the web gives me the answer to use setText("") but this do not really resets the Text IT only does empty the Text.
So i cant See the Default Text, declared in my xml... So Do you habe any Idea?
You can save your default value in the "res/values/strings.xml" like this
<string name="default">Your default string here</string>
You can use this value from xml like this:
<TextView
...
android:text="@string/default"/>
You can use it from code too.
textView.setText(R.string.default);
How about having a string resource as the default value? Save it in your strings.xml file:
<string name="def_value">my default value</string>
So:
<TexView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/def_value" />
Then in your code you can reset it like so:
TextView myTextView = (TextView) findViewById(R.string.myTextView);
myTextView.setText(getString(R.string.def_value));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With