Extract phone number from TextView text - android

I have a TextView with following words:
Google LLC is an 123 American multinational technology 456 company that specializes in Internet-related services and products. These include online advertising technologies, search, cloud computing, software, and hardware. Google was founded in 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University. Please call (123) 4444-3343
I want to make the number (123) 4444-3343 to a clickable one and taps it will have the user go to the calling mode.
I have tried following code:
textView.setAutoLinkMask(Linkify.PHONE_NUMBERS);
textView.setMovementMethod(LinkMovementMethod.getInstance());
It doesn't work at all. I only want the (123) 4444-3343 to be clickable. How can I achieve this? Thanks.

first option u have is to add in your XML android:autoLink="phone" to your textView
the second option u have is to use Html.fromHtml
txt.setText(Html.fromHtml("..." +
"Please call (123) 456-7890"));
txt.setMovementMethod(LinkMovementMethod.getInstance());
txt.setAutoLinkMask(Linkify.PHONE_NUMBERS);
another way is to use ClickableSpan more info u can find here
How to set the part of the text view is clickable and here

Related

country code validation with + symbol, Android

In my application users enters mobile number's country code with '+' symbol. Right now I am checking for + symbol. If they enter '+INDIA', according to my code this is correct. But according to logic this is wrong. They needs to enter '+91'. Means they can enter only 1, 2 or 3 digit number with '+' symbol. for example '+1', '+91' or '+234'. How I can achieve this type of validation in android?
You could write your own Pattern to check the format. I could give you the example, but I think the site I linked explains it much better.
It should probably start with something like \+\d\d?\d?
You could try using Google's own implementation of Phone Numbers or this xml list.
Hope it helps !

How to unhyperlink links programmatically?

I have a large body of text that includes web urls and emails. I created a SpannableString object and used Linkify class to set up hyperlinks for the web urls and emails. However, perceived phone numbers also get linked. So even though I have instances of 5-digit numbers such as "12345", this numeric sequence also are being linked. When clicked, a prompt comes up asking to call the number. Linkify thnks it is a phone number. How can I go back through and un-link specific text that I know should not be linked?
Here is how I have linked everything
final SpannableString s = new SpannableString(context.getText(R.string.message));
Linkify.addLinks(s, Linkify.WEB_URLS);
textView.setText(s);
textView.setMovementMethod(LinkMovementMethod.getInstance());
Thank you in advance.

Html content in android not displaying in textview android

I am working on android applications. In my app I am getting the html content and setting it to text view. My html data is displaying in the textview but at one point it stopped. i .e only half of the paragraph is displaying in the textview.
The data is
"The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite (TCP/IP) to serve several billion users worldwide. It is a network of networks that consists of millions of private, public, academic, business, and government networks, of local to global scope, that are linked by a broad array of electronic, wireless, and optical networking technologies. The (water A1c <5.0) may be detrimental in certain populations, such as the elderly and those with cardiovascular disease."
In the above paragraph upto "The (water A1c" the data is displaying in the textview and from there the data is not displaying. Th remaning data is cutted. I tried to trim the data but it didnt work. Please give me any suggestions for this.
Mycode:
Textview.setText((Html.fromHtml(data)));
The below content is being cut in the textview. It is not displaying.
<5.0) may be detrimental in certain populations, such as the elderly and those with cardiovascular disease."
String htmlStr = "<b>" +
context.getResources().getString(R.string.yourText)+
"</b>";
textView.setText(Html.fromHtml(htmlStr));
TextView myTextview;
myTextview= (TextView) findViewById(R.id.my_text_view);
htmltext = <your html (markup) character>;
Spanned sp = Html.fromHtml( htmltext );
myTextview.setText(sp);
Try something like below.
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("Hello Everyone"));
Actually it is the problem with the < symbol.
Just use the ASCII value of < symbol. and that is <.
Take a look here for more ASCII values.
Hope this will help. :)
As Aby Mathew suggested, you can display your data in TextView if you replace < by its HTML equivalent
Code that can be used:
data=data.replace("<","<");
Textview.setText((Html.fromHtml(data)));
Hope it helps :)

How to auto fill an edit text in android application?

I am developing one android application. In which I have some Products and form to purchase that product. In the Order form I have one Edit Text as Product ( means product name) .
In my application user has to type Product name but I want to know that Is there any way that
the EditText field is autofilled with that particular Product like as in flipcart.
Any one knows then suggest me...
Thanks in advance...
When you want to populate it just call (after reading it in from the XML layout in this example):
EditText myTextBox = (EditText) findViewById(R.id.editBox);
myTextBox.setText("My Product Description");
If what you are looking for is an auto completion after they have started typing, then an AutoCompleteTextView is your best bet, replacing the EditText and providing the auto complete functionality
There is an example of this over at the Android Developers website:
http://developer.android.com/guide/topics/ui/controls/text.html#AutoComplete
you can use autocomplete textview for suggestion of your all the product names, refer this example http://saigeethamn.blogspot.in/2010/05/auto-complete-text-view-android.html
or you just want to show when app launches, use hint
android:hint="#string/enterproduct"
I Dont get u clearly..
Sooo.
If u want to show text that which user has to fill use Hint.
android:hint="Enter any Filpcart Item"
OR
If u need auto complete text then use above link #kumaand.
Here you can use "input type" in XML design according to the text field.
Add into the XML file
android:autofillHints="emailAddress"
or
android:autofillHints="password"

TextView to send email when clicked

I have a TextView with android:autoLink="email".
If I put my email address in there then a link appears that I can click.
How do I have different text appear (for example 'Send Feedback') instead of the email address but still behave the same when clicked?
Thanks
To achieve what I wanted required a different approach:
TextView feedback = (TextView) findViewById(R.id.TextViewSendFeedback);
feedback.setText(Html.fromHtml("Send Feedback"));
feedback.setMovementMethod(LinkMovementMethod.getInstance());
This basically places HTML in the TextView so I get a link saying 'Send Feedback' but clicking it opens the default email application.
Word of warning: Trying this in the emulator didn't initially work for me, saying it was unsupported. This was just because I didn't have an email account setup. Setting one up in the emulator made the link work as I wanted.
You can use both links and email if you set the following param in the TextView
android:autoLink="web|email"
the links will be opened in the browser and the mails will be sent by the default mail client
Another simple way in layout:
...
<TextView
android:id="#+id/tvTelefone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sobre_telefone"
android:textColor="#000000"
android:autoLink="phone" />
...
...
<string name="sobre_telefone">Contato: (45) 9145-0000</string>
}
Read more here: http://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink
It might be easier to create a button and inside your onClickListener() pull an email from maybe R.string.email.
Fro the Strings From strings.xml :
<string name="your_string"><![CDATA[ contact us at recipient#mail.com for more help.]]></string>
tvObject.setText(Html.fromHtml(getString(R.string.your_string)));
tvObject.setMovementMethod(LinkMovementMethod.getInstance());

Categories

Resources