Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reset textview to its default value?

Tags:

java

android

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?

like image 660
user3650191 Avatar asked Dec 12 '14 19:12

user3650191


2 Answers

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);
like image 126
Vigen Avatar answered Sep 30 '22 04:09

Vigen


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));
like image 30
Elyakim Levi Avatar answered Sep 30 '22 04:09

Elyakim Levi