URL as a link in listview in android - android

I am new to android and I am trying to contribute for an android project. There is listview of messages and when a user clicks and a specific message, another view opens and shows the details as shown in below image(android view).
All these information is being fetched from web and parsed. and link is not clickable on web view also as shown in below figure (webview),
It is not shown as hyperlink on webview. I think that is the reason its not showing as a link in android app too.
Can anybody help me with this? The code related to this can be found at : source
related files are:
\scraper\MessagesScraper.java ,
\scraper\SingleMessageScraper.java ,
\ui\messages.java
\ui\SingleMessage.java
Any help would be great. thanks in advance.

In your XMl wherever you define that particular TextView add the following to that TextView
android:linksClickable="true"
Also see How do I make links in a TextView clickable? if you want to for example hide the URL and just show some text for the link.
Edit: From what I can tell...
MessageScraper is using ThreeLineAdapter - https://github.com/pradeepb6/TuCanMobile/blob/master/src/com/dalthed/tucan/adapters/ThreeLinesAdapter.java You can see all the TextViews here and then go to the res folder and change them accordingly.
SingleMessageScraper seems to be just using standard ArrayAdapter and Androids Simple_list_Item_1 for the layout. http://developer.android.com/reference/android/R.layout.html#simple_list_item_1 So if you need to you'll need to make your own list_item layout for this if it doesn't make sense to use one that was already created.
I don't think the UI classes need any changing.
Re: Comment - A single message (shown in your picture) is a listview of TextViews. You could also have a listview of custom views if you want more things in each cell, which is what the ThreeLineAdapter is handling.

If you are using TextView in your ListView's getView function,
you can use Linkify to convert the link to URL
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("http://www.example.com");
Linkify.addLinks(textView, Linkify.WEB_URLS);

WebView.getSettings().setJavaScriptEnabled(true);

Related

How to create nested textview using hyperlinks

I would like to create a FAQs as Help for my app. Currently my help section for my app is only one xml with an activity. The xml has only one textview and one return button. Now I want to change it to list of hyperlinks(FAQs), and when an user clicks on the hyperlink a text message(textview) should be displayed. How I can do this?
As for the list of FAQs. You can use a RecyclerView which you will provide to it the list of FAQ's you want to display.
For the message you can use a Toast, SnackBar or even use the hyperlink to open up in the browser itself.

Custom rendering for text with special syntax

I have a text gathered from API and it consists of custom syntax. I display it using TextView but I need to render special part of the text and convert those text into elements. An example of a text is below.
Oh, that's great idea! Check (user: someuser)'s answer for this.
You can as well look at (ref: a forum post title) or:
(ref: another forum post)
This is a hint for you! (hint: should be displayed as a mini icon
but when clicked, a tooltip should be opened)
Here is a spoiler for you.
---- spoiler ----
some spoiler. this text should not be displayed directly but it should be
converted to a button element. When the button is clicked, this text should
be shown
---- spoiler ----
So, I need to convert (user: someuser) into a link in the view which will be shown as "someuser" but when clicked, it will open a new intent. For (ref: topic) keyword, it's the same. When I hit spoiler, I want to make it a nice button indicating that it's a spoiler and when user clicks, it will expand.
How can I parse this text and show correctly in a view? I don't have problem with parsing but my problem is displaying those elements in the view.
Methods I Tried
I tried WebView instead of TextView thinking that I can convert those into HTML/Js but the performance was terrible. Although I use RecycleView and ViewHolder, WebView is simply an overkill. I need to use some kind of a TextView but with the elements I would like to have.
I also looked at custom HTML tag handling with TextView (thinking I can convert those legacy tags into html) but I failed to see how I can insert button for spoiler tag or insert custom elements like tooltip for hint.
Thank you!

Textview multiple underline text getting onClick dynamically in android

I should html content load on textview its ok and display well but how to handle multiple underline word getting onclick dynamically.
How can i getting click like as Phnom Penh, Siem Reap & so on etc..????
Thanks in advance
See snapshot
Just put below line in your code:
textview.setMovementMethod(LinkMovementMethod.getInstance());
It will open link which is attached to that word in html.
I'm so happy bcos I should find out answer for this quesiton, which i need to it dynamically solutions.
Just, go on this link for blog and step by step which is our need to dynamically solution there.
SuN Blog
http://suniljp.blogspot.in/search/label/TextView_%20%20underline%20text%20click
:)

Android - Insert large text in an Activity

i need to create an activity with the description on an object.
This description is about 1000 characters, on 16 line.
I wanna ask if there is some way or some rule to follow to insert a string big like this in a textview in android?
I only have to format in in the values/string file or i have to do something else?
And in this description there are some link, how can make them clickable? (when i click i wanna open my browser with the link).
To make links clickable just add this to your view :
android:autoLink="web"
Yes you just need to add that text to resources.
Best wishes.
Put the string in strings.xml, set it to a text view inside a scroll view so that it doesn't get hidden on smaller screens, set autoLink to make the links clickable.

Links and text in listview item

I like to recreate the behaviour of the textview containing the message of a user in the g+-app in my android project. To be exact:
- on click on a link the link is visually selected (blue selector) and will open up in the browser
- on click on normal text the whole list item is selected
The main problem I have, is, that every approach I tried to make links clickable (via xml and autolink=web, or in code) ends up, that the link opens up in a browser on click, but when I touch normal text in this textview the item is not selected (no selector is visible).
I read many threads about this issue, but all the solutions, like add setFocusable(false), etc. doesn't work for me.
So I want to ask, if there is any tutorial, how to or example, where I can see how this things work, or do you have any idea how I can get it to work?
Thanks! :)
if you have email id in textview use below code..
TextView email = (TextView)findViewById(R.id.TextView04);
email.setText("sasd asd#gmai.com sadasd");
email.setLinkTextColor(Color.WHITE);
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES);
if you have url in textview use below code...
TextView tv = (TextView)findViewById(R.id.TextView04);
tv.setText("sasd https://asd.com sadasd");
tv.setLinkTextColor(Color.WHITE);
Linkify.addLinks(tv,Linkify.WEB_URLS);

Categories

Resources