java - Showing clickable link inside of the textView -
does know how show clickable link inside of textview
(or appropriate view).that textview
located inside recycler row.
i getting string response json feed , inside string, there link webpage.
when user clicks link, want open browser , go page.
also trying handle click inside of onbindviewholder
method in recycler view adapter .
tried setting android:autolink="web"
in xml , setmovementmethod(linkmovementmethod.getinstance())
in java textview
, doesn't work , gives me error: " fatal exception: main android.util.androidruntimeexception: calling startactivity() outside of activity context requires flag_activity_new_task flag. want? "
if there better way handling these situations, please let me know.
use spannablestring.
for eg: going apply clickable register text(which has blue color underlined) means,
string text ="don't have account? register"; spannablestring spannablestring = new spannablestring(text); spannablestring.setspan(new foregroundcolorspan(getresources() .getcolor(r.color.blue)), 23, 31, 0);// applying register alone. starting count 23 , end count 31. clickablespan clickablespan = new spaceadjust(text) { @override public void onclick(view textview) { //here perform stuff } }; spannablestring.setspan(clickablespan, 23, 31, spanned.span_exclusive_exclusive);
if need make text clicable underline. use method.
import android.text.textpaint; import android.text.style.clickablespan; import android.view.view; /** * spaceadjust.java * * class used display underline text */ public class spaceadjust extends clickablespan { /** clicked. */ string clicked; /** * instantiates new space adjust. * * @param string * string */ public spaceadjust(string string) { super(); clicked = string; } /* * (non-javadoc) * * @see android.text.style.clickablespan#onclick(android.view.view) */ public void onclick(view tv) { // un used code .. implemented method } /* * (non-javadoc) * * @see * android.text.style.clickablespan#updatedrawstate(android.text.textpaint) */ public void updatedrawstate(textpaint ds) { ds.setunderlinetext(true); // if don't want use underline text, make false. } }
Comments
Post a Comment