如何设置多张click事件为单TextView的? [英] How to set mulitple click event for the single textview?
问题描述
我有一个TextView像下面这样:
I have a textview as like the following:
txtByRegistering.setText("By Registering you agree to terms and condition and privacy policy");
这只是一个大的文本。所以,我用滚动字幕的文字水平滚动。工作正常。我的问题是,如何同时单击选中的滚动文字调用click事件。
It is just a big text. So, I used marquee to scroll the text horizontally. that works fine. My Question is, How to invoke the click event while clicking the selected scrolling text .
说为前:
- 当用户点击这个词的的注册的在上面TextView的,我必须调用新的意图。
- 在当前这个词的用户点击的
条款
的后,我一定要
调用另一个新的意图(有作为的WebView的条款活性URL链接
)。
- when user click the word "Registering" in the above textview, I have to invoke the new Intent.
- When the user click on the word
"Terms"
, I have to invoke another new Intent (An Activity with webview as Terms hasURL Link
).
因为这个词注册和条款是Web网址,我想是这样如下:
As the word "Registering" and "Terms" are Web URLs, I tried something like below :
String mRegDesc = "By registering you agree to the " + "<a href=\""
+ Constant.URL + "/terms_and_conditions"
+ "\">Terms of Use</a> " + "and " + "<a href=\"" + Constant.URL
+ "/privacy" + "\">Privacy Policy</a> ";
txtByRegistering.setText(Html.fromHtml(mRegDesc));
txtByRegistering.setMovementMethod(LinkMovementMethod.getInstance());
txtByRegistering.setSelected(true);
txtByRegistering.setTypeface(mTyFaceOverLockReg, Typeface.BOLD);
以上code工作正常,它带给我的浏览器当我点击单词条款,但我希望去新的活动。
The above code works fine and it brings me to the browser when i click the word "Terms" But i wish to go to new Activity.
希望你们能帮助我了!
谢谢,
hope you guys can help me out! thanks,
推荐答案
最后,
我找到了该解决方案,
下面是解决方案:
SpannableString SpanString = new SpannableString(
"By Registering you agree to the Terms of Use and Privacy Policy");
ClickableSpan teremsAndCondition = new ClickableSpan() {
@Override
public void onClick(View textView) {
Utils.displayToast("Clickable span terms and codition",
SignUp.this);
Intent mIntent = new Intent(SignUp.this, CommonWebView.class);
mIntent.putExtra("isTermsAndCondition", true);
startActivity(mIntent);
}
};
ClickableSpan privacy = new ClickableSpan() {
@Override
public void onClick(View textView) {
Utils.displayToast("Clickable span terms and codition",
SignUp.this);
Intent mIntent = new Intent(SignUp.this, CommonWebView.class);
mIntent.putExtra("isPrivacyPolicy", true);
startActivity(mIntent);
}
};
SpanString.setSpan(teremsAndCondition, 32, 45, 0);
SpanString.setSpan(privacy, 49, 63, 0);
SpanString.setSpan(new ForegroundColorSpan(Color.BLUE), 32, 45, 0);
SpanString.setSpan(new ForegroundColorSpan(Color.BLUE), 49, 63, 0);
SpanString.setSpan(new UnderlineSpan(), 32, 45, 0);
SpanString.setSpan(new UnderlineSpan(), 49, 63, 0);
txtByRegistering.setMovementMethod(LinkMovementMethod.getInstance());
txtByRegistering.setText(SpanString, BufferType.SPANNABLE);
txtByRegistering.setSelected(true);
由于傻眼pourvatan。
thanks to Shayan pourvatan.
这篇关于如何设置多张click事件为单TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!