java - Android: Open alertdialog from part of string? -
i have checkbox string says "i have read , understood terms , conditions". want make words "terms , conditions" link opens alertdialog terms , conditions can read. nothing special.
i'm thinking in line of:
<string name="cont_agree">i have read , understood <a ref="open alertdialog">terms , conditions.</a></string>
is possible, , should use says "open alertdialog"? if can't done way, how should do?
addition: open url use code:
<string name="cont_agree"><a ref="http://www.stackoverflow.com">stackoverflow</a></string>
but how open alertdialog, or screen, string? have seen apps possible, of course, how?
edit: code use spannablestringbuilder:
spannablestringbuilder text = new spannablestringbuilder(); text.append(getstring(r.string.before)); //now create clickablespan clickablespan clickablespan = new clickablespan() { @override public void onclick(view view) { d.show(); //here dialog displayed } }; //now append tos string text.append(getstring(r.string.popup)); //declare "tos" string clickablespan text.setspan(clickablespan, getstring(r.string.before).length(),getstring(r.string.before).length()+getstring(r.string.popup).length(), 0); //check on api setspan method ((checkbox)findviewbyid(yourview)).setmovementmethod(linkmovementmethod.getinstance()); ((checkbox)findviewbyid(yourview)).settext(text, buffertype.spannable);
i still markers @ first "text.append" line. multiple markers @ line:
- return type method missing
- syntax error on token ")", { expected after token
- r.string.before cannot resolved type
- syntax error on token ")", invalid variabledeclaratorid
- syntax error on token "append", identifier expected after token
first setup dialog
dialog d = new dialog(context); d.settitle... etcetc
in values.xml create 2 string
<string name="before">i have read , understood the</string> <string name="popup">tos</string</string>
now can use spannablestringbuilder
spannablestringbuilder text = new spannablestringbuilder(); text.append(getstring(r.string.before)); //now create clickablespan clickablespan clickablespan = new clickablespan() { @override public void onclick(view view) { d.show(); //here dialog displayed } }; //now append tos string text.append(getstring(r.string.popup)); //declare "tos" string clickablespan text.setspan(clickablespan, getstring(r.string.before).length(), getstring(r.string.before).length()+getstring(r.string.popup).length(), 0); //check on api setspan method ((checkbox)findviewbyid(yourview)).setmovementmethod(linkmovementmethod.getinstance()); ((checkbox)findviewbyid(yourview)).settext(text, buffertype.spannable); //aaaand we're done!