android:autoLink is not working in ButtonView in Android? - android

I have used autolink in ButtonView like below,
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email"
android:autoLink="email"
/>
if I used string like below I am able to go to email,
<string name="mail">abc#gmail.com</string>
But If I do like below, not happening,
<string name="mail">Send Mail</string>
That is the problemmm...
but nothing happened on clicking button...
When I used autolink for textView worked perfectly.. But why not working for Button???Thanks in advance

Hai Sandhiya you can use Linkify class to achieve your needs. try that one

Solved my problem when doing like below,
mailRedirectButton.setAutoLinkMask(0);
String content="<a href =mailto:abc#gmail.com>Send</a>";
mailRedirectButton.setText(Html.fromHtml(content));
mailRedirectButton.setMovementMethod(LinkMovementMethod.getInstance());
Referred here https://stackoverflow.com/a/33709981/12273964
Thank you for everyone who tried to help me..

Related

Creating a hyperlink within a textview inside a fragment

I have looked through many of the threads on this site to find the solution to my problem but none seem to work. At the moment I am able to create a hyperlink while displaying the website eg - Please go here - www.google.com (The www.google.com is hyperlinked). What I am trying to do is have the link as - Please go here (Here is the link). Below is the code i have tried but once I remove the link itself, the 'here' still highlights like a link but has no function.
Strings.xml:
<string name="goog">Please go here</string>
fragment_home.xml:
<TextView
android:id="#+id/npd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:autoLink="web"
android:fontFamily="sans-serif-light"
android:linksClickable="true"
android:text="#string/npd"
android:textColorLink="#FF0000"
android:textSize="12dp" />
If i change 'here' for www.google.com within Strings.xml, the link takes me directly there. Has anyone been able to figure this problem out yet? Thanks in advance.
Try this and let me know is it what you are looking for
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

suggested words in autocomplete not visible?

when i try to use autocomplete textview it works but all the suggested words have white color and when i clicked on them it s possible to see what is that suggestion
what should i do for this problem?
<AutoCompleteTextView
android:id="#+id/etBrand"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Brand"
android:inputType="textAutoComplete|textAutoCorrect"
android:textColor="#000000"
android:textColorHighlight="#android:color/black" />
what should i add to this xml code to solve this problem?
thanks in advance...
This a logged bug,
You can find some ways to fix it in the same link.
Auto complete text view
bug
Bug
solution
I hope it helps...
source: https://stackoverflow.com/a/8471078/1932105
please use the search before asking next time.

Why isn't the hyperlink clickable?

I'm writing an app that among other things displays HTML-formatted code in a TextView.
The problem I'm having is that although it does format the HTML to look as it should the hyperlinks included in the text are not clickable.
Anyone got any idea why?
This is what I've used:
contentText.setText("\n" + Html.fromHtml(HomeScreen.offer_description[offerSelected]));
contentText.setMovementMethod(LinkMovementMethod.getInstance());
And in the .xml files:
<TextView android:id="#+id/contentText"
android:autoLink="all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#color/black"/>
Any help would be great...thanks a lot!
which android api you are working on?
This code should do fine. (working for me atleast).
If not, try android:linksClickable="true" in the textView declaration

android changing text view (is this code ok?)

Can some one help me, I have heard alot of things and I dont know what to believe. I am making an app that is a counter. In my xml layout i have a TextView acting as a counter and the text is set by a string in strings.xml and i am controlling what the text view says from my java file. here is some code snip its. all I want to know is this ok?, it works fine but I want to know is it a bad or good way.
"counter" equals a variable.
"display" is referencing the ID of the textview"
what i am using to control the text view.
display.setText(String.valueOf(counter));
here is my text view in my xml layout
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDisplay"
android:gravity="center"
android:text="#string/counter"
android:textSize="20dp" />
here is the string in strings.xml
<string name="counter">0</string>
It's fine, that's how you change text dynamically.
Yes, All things are right and good. Yo should have to give the String Value as like that.
If there is a Small Value of TextView then you can directly give as android:text="abcd"
And If you want to give any reference of that then your code is also correct and works as well.
For the Best use of coading your should have to try as like you have done rightnow. as Because it helps you a lot if there are number of TextView and you want to manage or change the Value of it quickly.
Enjoy. :)
Thanks.

Hyphen breaks the line into multi line

In a a custom list view, I have a textview showing name and emailId. When the name provided is something like A-TestThisString(testA#test.com), the length of displayed area exceeds,
In that case the string is broken at the place of hyphen like
A-
is shown in the list. This is causing lots of problems. I have found one link which talks about solution bellow
topic: "Android: How do i make nonbreakable block in TextView?"
but, I am not able to understand how to use it. Please suggest.
Thanks for your help. I found the answer. use the inputType as email or singleLine=True, it starts working fine.
I used android:inputType="date", no line breaks and hyphen is displayed nicely
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="2-3 4-5"
android:inputType="date"
android:textSize="25sp" />

Categories

Resources