Ignacio Perez Ignacio Perez - 1 year ago 156
Android Question

How can I use android studio Textview and have string data while dynamic data on same line

I am new to android studio and have a TextView which has a hardcoded strong and I have a dynamic variable that I want to put at the end of the string but do not know how to do it for example this is my code..

android:text="@string/Generic_Text"+"@{ Profile.name }" />


I am having an issue with android:text="@string/Generic_Text"+"@{ Profile.name }" . The Generic_Text states " My Name is " then the Profile.name is dynamic and obviously changes from profile to profile. I want it so that the whole TextView output is My Name is {Profile.name} any help would be great.

Answer Source

You can do this:

android:text= "@{String.format(@string/Generic_Text, Profile.name)}"

if you use string formatting for your Generic_Text string. ex. %s at the end

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download