putting hyperlinks in TextViews - but not knowing the address in advance - android

I need to localize an Android app in many languages. But the text also contains a local web link like www.theLink.com, www.LinkForOtherLanguage1.it, www.yetAnotherLinkForOtherLanguage2.fr,... you get the idea :)
I know this way to linkify...
Pattern pattern = Pattern.compile("www.theLink.com");
Linkify.addLinks(textView, pattern, "http://");
But here I need to know the addresses and put them in the code. Is there any way without changing the code for each language?
Many thanks

You could put the links in a string array and get them by position according to what language it is

Related

How to make a part of a text clickable (appcelerator, android)

I am trying to achieve a functionality where user can click a part of a text such as the username or a hashtag in a string which is used by most social apps.
There doesn't seem to be a way as of now.
Any help will be most appreciated.
Ti SDK 5.2.2
Android
Try to use an AttributedString. It allows you to display "html" like text. There is an easy to use module: https://github.com/FokkeZB/ti-html2as where you can set HTML text and it will convert it to an AttributedString.
So you would use a regular expression to convert you clickable elements (e.g. #element -> #element) and check for the click response

Android Too many ID

I'm building an Android app and I begin to have too many Id resources.
I wondered if there would be a way to have for example
TextView text = (TextView) findViewById(R.id.activity_name.item)
Thank you
This is not possible to my knowledge as the R class is generated and should not be edited.
But I think you can do the next best thing and make your naming convention match that format with underscores.
for example for all of your id's on the main page, this could be the text on a list element. MainPage_List_Text
Here is another so page you might find useful. Are there conventions on how to name resources?

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 can I store a spanned string in sqlite?

In Android, I have an application that handles multiple rich format text fields. I get the description of the text from an xml and create it as an spannable string builder, adding each run and styling it.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I know it can be done in iOS but I haven't found a way for Android.
Thanks in advance for any answers or tips.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I do not know what "the whole XML describing the paragraph" is. You can:
Use Html.toHtml() to generate HTML from a Spannable, or
Roll your own code to convert a Spannable into something that can be stored as a string or byte array

how to add smilies/emotions in my edittext for a notes app in android?

can any one know about how to add/insert emotions/smiles to text(which ever i typed in my edit text for my notes). i have little confusion about if i want to add these smiles of type .png in to edit text type of string, is it possible? and also i have to save these input into sqlite database. normally i know to store string data taken from edit text.
but along with that text i want to also add smiles symbols where ever my cursor placed and to be store in sqlite data base. and get it back to read.
so guys any ideas, most welcome!
Try to use java (i.e. android) spannable method to implement smiley (i.e.) images for that. You will surely get it, search in google for "how to add images/smiley with java spannable method in android?" you will get good idea.
Reading your question the first thing I can think of is Mapping each image to a sequence of letters, for example :) is smiley.png etc. Now your database also has these smaller representation However while reading from the database you can convert those special character sequences to appropriate image.
For simplicity in seraching those Strings You can wrap them in some less used characters i.e. [ or { or <.

Categories

Resources