fweigl
fweigl

Reputation: 22008

Clickable phone number in TextView

I have a String that might contain a phone number and I want that phone number to be clickable so the dial pad comes up when clicked. I achieved this with

        textView.setAutoLinkMask(Linkify.PHONE_NUMBERS);

Problem is on Android 2.3 the following phone number: 555/1233 only the numbers 555 will be part of the link. I know I could just filter the slash out of my phone number String but I wonder if theres a method to keep the slash in and still have the whole number linkified.

I found the class sPhoneNumberTransformFilter but I don't know how to use it here.

Any help?

Upvotes: 0

Views: 1981

Answers (2)

Dage
Dage

Reputation: 236

TextView myCustomLink3 = (TextView) findViewById(R.id.test);
Pattern pattern3 = Pattern.compile("[0-9]{3}/[0-9]{3}");
myCustomLink3.setText("123/999");
Linkify.addLinks(myCustomLink3, pattern3, "tel:", null, filter);

}

Linkify.TransformFilter filter = new TransformFilter() {
    @Override
    public String transformUrl(Matcher match, String url) {
        return url;
    }
};

Upvotes: 0

Sunil Mishra
Sunil Mishra

Reputation: 3826

You could do it this way

Linkify.TransformFilter filter = new TransformFilter() {
    @Override
    public String transformUrl(Matcher match, String url) {
        return url.replaceAll("/", "");
    }
};

Pattern pattern = Pattern.compile("[0-9/]+");
Linkify.addLinks(tv, pattern, "tel:", null, filter);

Upvotes: 1

Related Questions