Pradeepb
Pradeepb

Reputation: 2562

URL as a link in listview in 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).

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),

web view

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.

Upvotes: 3

Views: 4565

Answers (3)

thurst0n
thurst0n

Reputation: 155

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.

Upvotes: 1

Thinsky
Thinsky

Reputation: 4246

WebView.getSettings().setJavaScriptEnabled(true);

Upvotes: 0

Christian Abella
Christian Abella

Reputation: 5797

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

Upvotes: 1

Related Questions