The following code don't work-
TextView myLocation = new TextView(this);
myLocation.setText("Sodala, Jaipur, Rajasthan, IN");
Linkify.addLinks(myLocation , Linkify.MAP_ADDRESSES);
mainLayout.addView(myLocation);
It seems your address is too vague for Linkify. I am unaware of what addresses look like in India (if they are different at all), so consider New York in the US:
myLocation.setText("New York, NY 34 Maint St New York, NY");
"New York, NY" alone is not a valid map address for Linkify.
You can try to set your own pattern, by following an example here to match anything with ", IN".
Here is a simplified version of addLinks with a custom pattern.:
Pattern pattern = Pattern.compile(".*", Pattern.DOTALL);
addressTextView.setText(address);
Linkify.addLinks(addressTextView, pattern, "geo:0,0?q=");
I use this for german and US addresses, since google-maps is pretty smart when searching an address other localities should work find too.
This highlight's all the content's of the TextView which fits my use-case. If the address is somewhere inside of the string a smarter pattern needs to be applied here.
you try
http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/
// Recognize all of the default link text patterns
Linkify.addLinks(text, Linkify.ALL);
or
http://www.aviyehuda.com/2011/01/android-creating-links-using-linkfy/
TextView myCustomLink2 = new TextView(this);
Pattern pattern2 = Pattern.compile("[a-zA-Z]+");
myCustomLink2.setText("press one of these words to search it on google: Android Linkify dzone");
Linkify.addLinks(myCustomLink2,pattern2, "http://www.google.ie/search?q=", myMatchFilter, null);
Related
I want to have my phone number to be clickable, right now my current solution:
final SpannableString msg = "Contact us: test#t.t or call: 5008 878 6578"
Linkify.addLinks(msg, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS);
textView.setText(msg);
This works fine for Android 8.1 and below but not for Android 9 (email is clickable so the problem is only with number phone)
I've tried already doing it with XML layouts or with
textView.setAutoLinkMask(Linkify.PHONE_NUMBERS)
And the output is the same, phone number is not clickable.
How to fix it on Android 9?
The mask Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS seems correct, according to the documentation - but I would not recognize something alike 5008 878 6578 as a valid phone number - and I definitely could not dial it, if I would click it... so most likely the sPhoneNumberMatchFilter might be at fault.
Manually building the desired Spannable with the tel://50088786578 might be an easy solution; adjusting the sPhoneNumberMatchFilter might be the other option... also .addLinks() permits this, with argument matchFilter.
Are you certain that you are running with the same Locale on Android 9.0? This should be where the regex pattern to match for may come from, because those formats count towards localization.
FormattedString t = new FormattedString();
t.Spans.Add(new Span() { Text = "About my Self\n\n" });
t.Spans.Add(new Span() { Text = "1. My website\n\n" });
t.Spans.Add(new Span() { Text = "2. My Linkedin profile\n\n" });
t.Spans.Add(new Span() { Text = "3. Twitter\n\n" });
I have a Text like above, I am able to set hyperlink whole text but I want to set a hyperlink for website and Linkedin words with some URL.
How can I set hyperlink for particular word in Paragraph for Label
Please help me on that.Thanks!!
As far as I know, there is no way to do that, your best choice is to create multiple labels or add a gesture recognizer for the whole text, wich would be a better idea since clicking on a small word is difficult on certain devices and the gesture recognizers on Xamarin are not the best ones around.
This might help for you: AwesomeHyperLinkLabel . I myself looking way to implement this and will start with this link, but I want to improve it a bit and replace links text with friendly text so instead direct link to page it would say "my page"
I have a webview in an ios app that basically has no id or class. (I know, right?)
But it does have a textContent field that I would like to use to select elements.
This is the element I want to find:
{"rect"=>
{"center_x"=>307.5,
"left"=>295,
"bottom"=>136,
"right"=>320,
"top"=>93,
"width"=>25,
"height"=>43,
"center_y"=>178.5},
"nodeName"=>"LI",
"id"=>"",
"textContent"=>"!!! I WANT TO FIND IT BY THIS !!!",
"center"=>{"X"=>307.5, "Y"=>178.5},
"nodeType"=>"ELEMENT_NODE",
"webView"=>
"<UIWebView: 0xe2e1400; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = W+H
"class"=>"arrow",
"html"=>"<div class=\"arrow\"></div>"}
So I was able to find this using css pseudo-selectors alá
query("webView css:'el:first-child'")
I can find it by using the hashes in the results array alá
query("webView css:'li'").select {|element| element["textContent"] == "!!! I WANT TO FIND IT BY THIS !!!}
And I can refactor it a bit to use a regex alá
query("webView css:'li'").select {|element| element["textContent"] =~ /I WANT/}
But all this feels really dirty. Very un-Calabashy. Is there a better way to write this?
I have not tried your exact setup. But I do often use queries with the LIKE comparison on label.
Would that solve your problem?
ex.
element_exists("label {text LIKE 'I WANT TO FIND'}")
I wound up going with this:
query("webView css:'TITLE'{textContent CONTAINS ’I WANT’}")
It tends to work more consistently with these particular webviews (given a lack of accessibility labels in the code).
I have a url:
https://<site name>/pallavi/[Songs.PK]%2002%20.mp3
I have a text view, with property: android:autoLink="all"
If I simply set the text to the text view, my text view simply highlights the portion preceding the [. It looks something like this:
https://< site name >/pallavi/[Songs.PK]%2002%20.mp3
What i want is, the whole link should be highlighted like:
https://< site name >/pallavi/[Songs.PK]%2002%20.mp3
What I have tried till now:
Used the < pre > tag and Html.fromHtml, but it doesn't seem to work! (I don't even know if the < pre > is supported in android though.)
Used Jsoup.parser. But that too doesn't seem to work for me.
UPDATE
I have tried this answer too: https://stackoverflow.com/a/12376115/1320263
Please let me know if the issue is with android that the text view's linkAll property itself does not consider parenthesis as a valid character or not? If it is supported, how do i hyperlink that too?
Also NOTE:
The text(or link) I have written in the question is just a sample text. In reality, I am getting a block of text, from where it would be very difficult to identify where exactly the hyper link starts and where it ends. Also, the number of links present in the block would be un-known. Hence I cannot use the < a href = "" > thing...
If some one else happens to have the same issue, following is the solution which worked for me:
Pattern pattern = Pattern.compile("(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))");
SpannableString spannable = new SpannableString(html);
Matcher matcher = pattern.matcher(spannable);
// Create ActivitySpans for each match
while (matcher.find())
spannable.setSpan(new ActivitySpan(matcher.group()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// Create a new TextView with these spans and enable the clickable links
mTxtEventDescription.setText(spannable);
You can try this:
((TextView) findViewById(R.id.your_text_view)).setMovementMethod(LinkMovementMethod.getInstance());
((TextView) findViewById(R.id.your_text_view)).setText(Html.fromHtml(getResources().getString(R.string.string_with_links)));`
I have the following TextView in my XML layout file:-
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/autolink_test"
android:autoLink="all"
/>
The string autolink_test contains a phone number, an email address, a website address and a physical geographical address.
While the first three are showing up correctly as clickable autolinks, the address does not. Only the zipcode part shows up as an autolink... and that too as a phone number! (When I click it, the phone dialer starts up with that number).
Any help would be appreciated.
Alternative to it, in case if autolink doesn't work
Add links to your texview . Get it underline as folows :
SpannableString spanStr = new SpannableString(buf.toString());
spanStr.setSpan(new UnderlineSpan(), 0, spanStr.length(), 0);
iTextView.setText(spanStr);
Use the following code to open it with map app on click as follows :
Intent geoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="
+iTextView.getText().toString()));
startActivity(geoIntent);
OK, I figured out what was causing the problem. Just thought I will leave the answer here in case someone else runs into the same problem.
If the street address is not properly capitalized, it is not read properly as the address!
Here is my XML autolink_test string:
<string name="autolink_test">Name: New York Times \n
Email: public#nytimes.com \n
Phone: 212-556-7652 \n
Address: 620 Eighth Avenue New York, NY 10018 \n
Address: 620 Eighth avenue New York, NY 10018 \n
Website: http://www.nytimes.com
</string>
The first address shows up correctly as an autolink.
The second one (with a small 'a' in 'avenue') does not show up correctly.
This seems a little strange to me as the google maps website certainly doesn't care about such niceties.
Anyways, so here it is :-)