[mono-android] How to use abstract ClickableSpan

Stuart Lodge me at slodge.com
Mon Feb 6 15:21:19 UTC 2012


Ah OK - worked it out :)

Writing down the question helped :)

Thanks!

    public class CommandBasedClickableSpan : ClickableSpan
    {
        private readonly IMvxCommand _command;

        public CommandBasedClickableSpan(IMvxCommand command)
        {
            _command = command;
        }

        public override void OnClick(View widget)
        {
            _command.Execute();
        }
    }


On 6 February 2012 14:40, Stuart Lodge <me at slodge.com> wrote:

> I'm trying to write some code using ClickableSpan at present - a bit like
> the answer from
> http://stackoverflow.com/questions/8208702/androidautolink-in-listview (reproduced
> below)
>
> However, ClickableSpan seems to be abstract inside MonoDroid - so I can't
> new it.
>
> Anyone got ideas of a way around this? Should I just inherit and make my
> own span type? Should I be using something else like UrlSpan?
>
> All ideas welcome
>
> Stuart
>
> String styledText = getResources().getString(R.string.Email);
>
>     SpannableString span = new SpannableString(styledText);
>
>     span.setSpan(new StyleSpan(Typeface.ITALIC),
>
>             styledText.indexOf("Terms"), styledText.length(), 0);
>
>     span.setSpan(new UnderlineSpan(), styledText.indexOf("Terms"),
>
>             styledText.length(), 0);
>
>     ClickableSpan clickSpan = new ClickableSpan() {
>
>         @Override
>
>         public void onClick(View widget) {
>
>             // TODO Auto-generated method stub
>
>             showInfoDialog();
>
>         }
>
>     };
>
>     span.setSpan(clickSpan, styledText.indexOf("Terms"),
>
>             styledText.length(), 0);
>
>     span.setSpan(
>
>             new ForegroundColorSpan(getResources().getColor(R.color.link_)),
>
>             styledText.indexOf("Terms"), styledText.length(), 0);
>
>     txt_accept.setText(span, BufferType.SPANNABLE);
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodroid/attachments/20120206/203ba6ce/attachment-0001.html>


More information about the Monodroid mailing list