I have a Textview
with location:
eg. "Mountain View, CA"
What I want to achieve is to create this text to act like a Link - color,underline, focusability etc.
This link doesn't need to direct anywhere - surrounding view has attached onClick listener that fires google maps intent.
Something like this should work.
TextView location = (TextView) findViewById(R.id.location);
location.setMovementMethod(LinkMovementMethod.getInstance());
Spannable spans = (Spannable) location.getText();
ClickableSpan clickSpan = new ClickableSpan() {
@Override
public void onClick(View widget)
{
//put whatever you like here, below is an example
AlertDialog.Builder builder = new Builder(MainActivity.this);
builder.setTitle("Location clicked");
AlertDialog dialog = builder.create();
dialog.show();
}
};
spans.setSpan(clickSpan, 0, spans.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With