TextView to send email when clicked - android

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());

Related

Extract phone number from TextView text

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

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"

Android-Is it possible to add a clickable link into a string resource

I usually set up some kind of AlertDialog to fire off when a user first uses one of my apps and I explain how to use the app and give an overall introduction to what they just downloaded. I also usually load my strings from a strings.xml file.
What I want to do is make one of the words in my string resource clickable like a hyperlink on a web page. Basically you'd have an AlertDialog and within the string resource there would be a highlighted word or possibly just a web address that they could press. I suppose I could just add a button that would take them to the site but I just wanted to know if making a word in your string resource a clickable hyperlink was possible.
Just use an HTML format link in your resource:
<string name="my_link">Click me!</string>
You can then use setMovementMethod(LinkMovementMethod.getInstance()) on your TextView to make the link clickable.
There is also TextView's android:autoLink attribute which should also work.
I found something interesting. Let me know if any of you observed this.
Below hyperlink is not working if you use
android:autoLink="web"
but works with
TextView link = (TextView) findViewById(R.id.link);
link.setMovementMethod(LinkMovementMethod.getInstance());
<string name="my_link">
<a href="http://stackoverflow.com/questions/9204303/android-is-it-possible-to-add-a-clickable-link-into-a-string-resource">
Click me!
</a>
</string>
but if you use the following link it works with both
android:autoLink="web" (or)
TextView link = (TextView) findViewById(R.id.link);
link.setMovementMethod(LinkMovementMethod.getInstance());
<string name="my_link">
<a href="http://stackoverflow.com/questions/9204303/android-is-it-possible-to-add-a-clickable-link-into-a-string-resource">
http://stackoverflow.com/questions/9204303/android-is-it-possible-to-add-a-clickable-link-into-a-string-resource
</a>
</string>
As answered by #Nikolay Elenkov In Kotlin I used it from string resources in this way (detailed way for freshers):
in my layout place a checkbox:
<CheckBox
android:id="#+id/termsCB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="#dimen/spacing_normal"
android:layout_marginTop="#dimen/spacing_normal"
android:text="#string/terms_and_conditions" />
in strings.xml
<string name="terms_and_conditions">I read and accept the Terms and Conditions</string>
in my activity class inside the onCreate() method:
termsCB.movementMethod = LinkMovementMethod.getInstance()
Android doesn't make strings that contain valid link clickable automatically. What you can do, is add custom view to your dialog and use WebView to show the alert message. In that case, you can store html in your resources and they will be clickable.
View alertDialogView = LayoutInflater.inflate(R.layout.alert_dialog_layout, null);
WebView myWebView = (WebView) alertDialogView.findViewById(R.id.dialogWebView);
myWebView.loadData("Google!", "text/html", "utf-8");
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
builder.setView(alertDialogView);
alert_dialog_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/dialogWebView" android:layout_height="wrap_content"
android:layout_width="wrap_content" />
For me, the hyperlink always works well, when I:
Add these two lines to the activity/fragment:
textView.setMovementMethod(LinkMovementMethod.getInstance())
textView.setText(Html.fromHtml(getString(R.string.link)))
Do not add anything to the xml (like autoLink etc).
Define link in strings.xml like
<string name="link"><![CDATA[Google link]]></string>

problem with linkify in android app

I have a phone number in a text view (thats the only thing I have there). I am using :
Linkify.addLinks(textView, Linkify.ALL);
However, the phone number is not being recognized by linkify. The number is of the format:
(123) 456-7890. I have also tried 1234567890 and 123.456.7890. Nothing works. Any help ?
thanks.
In your XML file of your Text View add an attribute android:phoneNumber="true"
Try this in the Click of the Text View :
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:"
+ your_phone_number)));
Automatically the Text will have the property of Phone number.
Since you are trying something that is custom refer to this doc
http://developer.android.com/resources/articles/wikinotes-linkify.html
it will help you.

Can't get HREF to work in Android strings.xml

I'm trying to add a link to a Twitter profile in an about box. 'Regular' links such as email address and web address are handled by
android:autoLink="email|web"
in about.xml, but for a Twitter profile page I need to use html code in my strings.xml. I've tried:
<string name="twitter">Follow us on <a href=\"http://www.twitter.com/mytwitterprofile">Twitter: #mytwitterprofile</a></string>
which renders html markup on the about box.
I've also tried:
<string name="twitter">Follow us on Twitter: #mytwitterprofile</string>
which display the text "Follow us on Twitter: #mytwitterprofile", but it is not a hyper-link.
How do I do this seemingly simple task!?
Cheers,
Barry
The problem is your "a href" link tags are within strings.xml and being parsed as tags when strings.xml is parsed, which you don't want. Meaning you need to have it ignore the tags using XML's CDATA:
<string name="sampleText">Sample text <![CDATA[link1]]></string>
And then you can continue with Html.fromHtml() and make it clickable with LinkMovementMethod:
TextView tv = (TextView) findViewById(R.id.textHolder);
tv.setText(Html.fromHtml(getString(R.string.sampleText)));
tv.setMovementMethod(LinkMovementMethod.getInstance());
The simple answer is that the TextView does not support <a> tags. AFAIK, it only supports basic formatting such as <b>, <i> and <u>. However, if you supply android:autoLink="web", the following string:
<string name="twitter">Follow us at twitter.com/mytwitterprofile</string>
Will turn twitter.com/mytwitterprofile into a proper link (when set via XML like android:text="#string/twitter"; if you want to set it from code, you'll need the Html.fromHtml method someone else posted in an answer).
I'm not too sure how to link using 'strings', but you could set text of the EditText or TextView using fromHtml...
TextView text = (TextView) findViewById(R.id.text);
text.setText(Html.fromHtml("Google Link!"));
text.setMovementMethod(LinkMovementMethod.getInstance());

Categories

Resources