如何为单个textview设置多次单击事件? [英] How to set multiple click event for the single textview?
本文介绍了如何为单个textview设置多次单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下文本视图:
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 .
为ex辩护:
- 当用户在以上文本视图中单击 正在注册" 时,我必须调用新的Intent.
- 当用户单击单词
"Terms"
时,我必须 调用另一个新的Intent(具有Webview的条款"为URL Link
的活动).
- 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 URL,因此我尝试了以下操作:
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);
上面的代码运行良好,当我单击术语"一词时,它带我进入浏览器,但我希望转到新的活动.
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.
推荐答案
最后,
我找到了解决方法,
这是解决方法:
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) {
Intent mIntent = new Intent(SignUp.this, CommonWebView.class);
mIntent.putExtra("isTermsAndCondition", true);
startActivity(mIntent);
}
};
// Character starting from 32 - 45 is Terms and condition.
// Character starting from 49 - 63 is privacy policy.
ClickableSpan privacy = new ClickableSpan() {
@Override
public void onClick(View textView) {
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);
感谢Shayan pourvatan.
thanks to Shayan pourvatan.
这篇关于如何为单个textview设置多次单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文