Note that there are some explanatory texts on larger screens.

plurals
  1. POclickable word inside TextView in android
    primarykey
    data
    text
    <p>I have TextView with text that changed dynamically. This text contain strings like <code>&lt;a href='myWord'&gt;myWord&lt;/a&gt;</code>. I want that after click to this "link" myWord appear in the EditText in the same activity.</p> <p>This is my code:</p> <pre><code>txt.setText(Html.fromHtml("...&lt;a href='link'&gt;link&lt;/a&gt;...")); txt.setMovementMethod(LinkMovementMethod.getInstance()); </code></pre> <p>It's work well for URLs inside href attribute, but there is an error for another format.</p> <p>I found a lot of similar questions on the StackOverflow but all of them were about url links. In my app I want create "link" inside activity. In general, I can change tag to some another if it's depend...</p> <p>Please help me! Thank you!</p> <p>-----SOLVED----- Thank you Jacob Phillips for idea!</p> <p>May it will be interesting someone in future. This is a code:</p> <pre><code>//This is my string; String str = "&lt;b&gt;Text&lt;/b&gt; which contains one &lt;a href='#'&gt;link&lt;/a&gt; and another &lt;a href='#'&gt;link&lt;/a&gt;"; //TextView; TextView txt = new TextView(this); //Split string to parts: String[] devFull = data[v.getId()][1].split("&lt;a href='#'&gt;"); //Adding first part: txt.append(Html.fromHtml(devFull[0])); //Creating array for parts with links (they amount always will devFull.length-1): SpannableString[] link = new SpannableString[devFull.length-1]; //local vars: ClickableSpan[] cs = new ClickableSpan[devFull.length-1]; String linkWord; String[] devDevFull = new String[2]; for(int i=1; i&lt;devFull.length; i++){ //obtaining 'clear' link devDevFull = devFull[i].split("&lt;/a&gt;"); link[i-1] = new SpannableString(devDevFull[0]); linkWord = devDevFull[0]; cs[i-1] = new ClickableSpan(){ private String w = linkWord; @Override public void onClick(View widget) { // here you can use w (linkWord) } }; link[i-1].setSpan(cs[i-1], 0, linkWord.length(), 0); txt.append(link[i-1]); try{ txt.append(Html.fromHtml(devDevFull[1])); } catch(Exception e){} } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload