WojciechKo
WojciechKo

Reputation: 1531

How to get text defined in xml, after change it programmatically

I have TextView:

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Simple Name" />

Then I set text programmatically by amount.setText("other Name").
Now, is it possible to get original value from that TextView?
I know that I should use string resources and then there would be no problem but I'm curious is this possible.

Upvotes: 1

Views: 59

Answers (1)

Mark
Mark

Reputation: 5566

There is no way of getting this value from xml.

  1. Put your "Simple Name" to string resources as my_resource
  2. Use android:text="@string/my_resource" in your TextView
  3. Set text in the code to whatever you want tv.setText("Whatever")
  4. Set text in the code back to previous value tv.setText(R.string.my_resource)

Upvotes: 2

Related Questions