klinker24 / Android-TextView-LinkBuilder

Insanely easy way to define clickable links within a TextView.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to apply to different portion of text

shollynoob opened this issue · comments

Hello , please how can i apply this to different portion of text eg I want to apply this, that and this

i don't know if you understand what i mean, i want to apply to series of text

You just need to build links for the text that you want to "linkify". For example, if you wanted to add a click action to the text "click here" in the following sentence:

Please click here to view our terms of service.

You would create a link, as described in the sample app:

Link link = new Link("click here")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });

LinkBuilder.on(textView)
    .addLink(link)
    .build();

yes i was able to apply to one text, if i want to apply "click", "view", "terms" and "service" in your example above, can i pass a parameters or an "if" statement to the build link?

I don't really understand your question, sorry... Maybe an example use-case would be good.

You could apply more than one link onto LinkBuilder:

LinkBuilder.on(textView)
    .addLink(link1)
    .addLink(link2)
    .addLink(link3)
    .build()

i so much appreciate your response, and really new to programming sought off though.
let take for instance i have this statement The quick brown fox jumps over the lazy dog , and i want to add OnClickListener to "quick", "fox", "jump" and "dog" to handle different event.

See what i have below

Link a = new Link("quick");
Link b = new Link("fox");
Link c = new Link("jump");
Link d = new Link("dog")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });

TextView note = (TextView) findViewById(R.id.note);
LinkBuilder.on(note)
    .addLink(a)
    .addLink(b)
    .addLink(c)
    .addLink(d)
    .build(); 

How to get the click event for a, b, c, d is my issue

Well, you are setting up a click event for d already. You can do the same thing for a, b, and c:

Link a = new Link("quick")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });
Link b = new Link("fox")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });
Link c = new Link("jump")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });
Link d = new Link("dog")
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {

        }
    });

TextView note = (TextView) findViewById(R.id.note);
LinkBuilder.on(note)
    .addLink(a)
    .addLink(b)
    .addLink(c)
    .addLink(d)
    .build();