Question

I know how to give a hyper link to word, but now i need to give hyperlink to a word within a paragraph ?

For example my paragraph:

Lorem Ipsum is simply dummy text of the printing and "typesetting industry". Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Here i want to add hyper link to "typesetting industry" this word , is that possible?? if so please help me to get the solution.

Was it helpful?

Solution

I could do this using below code,

TextView textView = (TextView)findViewById(R.id.text);
        textView.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.");

        MatchFilter mMatchFilter = new MatchFilter() {
            public final boolean acceptMatch(CharSequence s, int start, int end) {
                return true;
            }
        };
        TransformFilter mTransformFilter = new TransformFilter() {
            public final String transformUrl(final Matcher match, String url) {
                return "www.google.com";
            }
        };

        Pattern mPattern = Pattern.compile("typesetting industry");
        String scheme = "http://";
        Linkify.addLinks(textView, mPattern, scheme, mMatchFilter, mTransformFilter);

OTHER TIPS

Dear Brindha use this for a particular text,you can set web or email or phone or map or all as per your requirement.

android:autoLink="web|email|phone|map|all"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top