2

I faced the following problem: there is the string resource which contains URL:

<string name="msg_more_information_about_credit"><![CDATA[<b>Ejemplo TAE:</b> 300€ a 62 días. <b>Coste préstamo:</b> 148€. <b>Total a devolver:</b> 448€. TAE 2035%. <a href="https://www.moneyman.es/secci.php?pers=0.011&tae=3112.64&back=290&back_date=22.11.2020&current_time=30&current_sum=290&is62=false">Más Información </a> ]]></string>

I need to make this link dynamic (pass values to it from code). For this purpose, I modified it a bit:

<string name="msg_more_information_about_credit"><![CDATA[<b>Ejemplo TAE:</b> 300€ a 62 días. <b>Coste préstamo:</b> 148€. <b>Total a devolver:</b> 448€. TAE 2035%. <a href="https://www.moneyman.es/secci.php?pers=0.011&tae=3112.64&back=290&back_date=%1$s&current_time=30&current_sum=290&is62=false">Más Información </a> ]]></string>

And then I tried to get resources as usual, when string contains other strings:

getString(R.string.msg_more_information_about_credit, "22.11.2020")

But in this case the link doesn't have my set value, but contains "%1$s"

So, my question is, how can I modify the link from code? Thanks in advance!

5
  • which data you want to pass dynamically? couldn't see "%1$s" Commented Aug 5, 2020 at 11:46
  • Have you tried to add formatted="false" to your string resource? stackoverflow.com/a/12627660 Commented Aug 5, 2020 at 11:47
  • @ShaluTD, I am trying to pass a string to back_date parameter Commented Aug 5, 2020 at 11:48
  • @BrunoBieri added formatted="false", but resut is the same Commented Aug 5, 2020 at 11:51
  • Have you also tried reading the string separately and in a second step to format it with String.format(getString(..), "22.11.2020") ? Commented Aug 5, 2020 at 12:08

1 Answer 1

2

Step 1 : Add string with link in your string.xml file.

<string name="mystringwithlink">Here is code how to put link into string xml \n<a href="https://stackoverflow.com">stackoverflow.com</a></string>

Step 2: Then enter below line of code in your_activity.java

val linkTextView = findViewById<TextView>(R.id.activity_main_link)
    
linkTextView.setMovementMethod(LinkMovementMethod.getInstance());

If works perfectly then leave upvote for encouragement.

REF : link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.