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
Related
I'm a newbie to Android and I have looked at similar questions asked by others without a definite answer, since, I think, my problem is a bit different.
I'm using a TextView in my program in which there can be links, text, numbers etc. following is the TextView I'm using.
<TextView
android:id="#+id/viewText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:autoLink="web"
android:linksClickable="false"
android:ellipsize="end"
android:maxLines="7" />
Although this is working for normal texts, the ellipsize does not work whenever links are present in the TextView. I'm using "autoLink" in order to show the user that it is link but had set android:linksClickable to false. Right now, I've added the ellipsize from the code but I want to know whether I can do it from the XML file itself.
Thank you.
I have a ListView and I'm trying to convert an HTML link tag to be clickable w/ a TextView.. I do not know what I'm doing wrong? It doesn't convert this:
String txt = "<a href='http://www.google.com'>Google</a>";
viewHolder.txtMessage.setMovementMethod(LinkMovementMethod.getInstance());
viewHolder.txtMessage.setClickable(true);
viewHolder.txtMessage.setText(Html.fromHtml(txt));
Additionally here's what the XML looks like:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:linksClickable="true"
android:autoLink="web"
android:textColorLink="#fff"
android:text=""
android:textIsSelectable="true"
android:id="#+id/txtMessage"
android:textColor="#android:color/white"
android:textSize="16dp" />
Edit
It's not the same as the other SO question. Their solution does not work w/ my use-case. My question is referring to getting the link to convert, while that question is refers to non-a tag html links. I do not know if it being in a listview has anything to do with it.
I have a textview which get text from server and that text is a full paragraph like and has a html format. Now i am using maxline=2 in xml to show some of the text in two lines. I have tried many tricks but nothing works. Here is my xml code, please tell me what going wrong with it?
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/subject"
android:layout_toLeftOf="#+id/date"
android:maxLines="2"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="#666666"
android:textAppearance="?android:attr/textAppearanceMedium" />
And this is how i set text into that textview.
message.setText(Html.fromHtml(details.Description()));
It always looks like this,
This is the text
that came from server
As you can notice above where the first line start from the second on not starting from there below. I want both to start from same position. The problem is text coming from server is a single sentence and i can't use "\n" or </br> like tags and also this text is in the listview setting by getview. And i have also tried android:gravity="center_horizontal" and android:layout_gravity="center_horizontal"
I have some RTL text (Hebrew) that I want to be aligned right inside the TextView. Currently the XML looks like this:
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingRight="10dp"
android:singleLine="false"
android:textColor="#FFFFFF"
android:textDirection="rtl"
android:textSize="12sp"
android:textStyle="bold" />
And it acually works great on Galaxy S3 Android 4.2.2 and I even tested it on a Galaxy S1 Android 2.3.3 and it was ok too. But on some devices, for example Galaxy S2 Android 2.3.5, it's aligned left for some reason.
I searched alot and I did not find and solution to this problem, I'd be happy if someone will show me a solution within the XML layout file, but programatcly solution can work as well.
I tired with your code.. you want to placed the text in right side of textview right?...
I'm pretty to help you because, I also gone through this issue..
In your code,
android:gravity="right"
Instead of this, try this
android:gravity="end"
I think this is what you are looking for
I tried to show a hint in the EditText of my form, but i can't see that hint that i have set in the XML Layout while my application gets deployed, but i can able see the hint in eclipse designer view, but while getting deployed the same hint suppose to appear is missing, i tried with all the possible ways still i could not get the hint in the EditText... This is one of the Edit Text layout that i have used..
<EditText android:id="#+id/SetTimerSec_EditText01"
android:layout_width="60sp"
android:layout_height="40sp"
android:singleLine="true"
android:layout_x="220sp"
android:layout_y="170sp"
android:hint="0"
android:inputType="phone"
android:textColorHint="#color/black"
android:gravity="center"
android:focusableInTouchMode="true" />
[link text][1]
Can anybody Help me..Please
Thanks in advance
[1]: http://imgur.com/PzomF.jpg
[ScreenShot of Designer View with hint displayed][1]
It seems like a SDK bug, or at least related to one.
http://code.google.com/p/android/issues/detail?id=7252
The hint shows up if you remove the following:
android:gravity="center"
add android:ellipsize="start" and your hint will show up and be centered!