Links and text in listview item - android

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

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.

Android: Why multiple links in TextView are highlighted?

I have textview in which multiple links are shown, the text is dynamic.
I have added following to textview
android:autoLink="all"
android:textColorLink="#color/selector_autolink_textcolor"
This makes all links in textview show a different color and show click color, but on click of textview all the links in textview show selected color, this confuses the user as he cannot identify what he's clicking.
How can I only highlight/show press-state of a single link when pressed.
I have two approaches for you to solve this problem.
First Approach:- This one is quite simple. You can use different TextView to display hyperlinks and display the links. On clicking them you can get different selector color
Second Approach:- Use can use Spannable concept in Android to achieve this. Break the string into different part to show different hyper links. You can achieve the different color slector based upon user click. You can follow this example more from here (see try Spannable part) Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView

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

Android ExpandableList Header with spinner

I'm developing an application and I am facing a problem using ExpandableListView. What I'm trying to do is, in GroupHeader, not only show the group name, but also an spinner with options. That's because I want to show the football second division games in the list but, also, give the option to choose the round, in case the user wants to check older/future games. SO far I have that
As you can see both, title and spinner, shows. Also you can see the arrow on the right which is supposed to expand the list. Problem is that, if I click, only spinner opens, group expand button doesn't. So, here is my question, how can I make both of them work depending on where you click (one or another)??? Is that possible?
Also I must say that if I only place the TextView with the group name works perfect. If I only place the spinner, the problem persists. So I'm guessing that's a focus problem.
Btw: grey areas are the layout backgrounds, so no, they are not hiding behind the button.
I found the solution, I just neede to add this line android:descendantFocusability="blocksDescendants" to the Main Layout of the xml where I define the GroupHeader elements.

AOSP: Non-focusable but LongClickable TextView

I just downloaded AOSP and modified TextView for my purpose.
I have added a LongClick Listener to the TextView, which shows a simple Toast.
Since I modified the Android framework, it is reflected into all the apps and entire Android OS.
I have now run into a weird issue where the TextView is getting focus in some places and other underlying widgets are not getting any focus. This is creating lot of issues.
For eg: In Settings app, The 'Wi-Fi' text is receiving focus, but I cannot enter the wi-fi settings unless I click in any empty area in the Wi-Fi list item.
(I hope am clear!)
Another example: I am unable to select the Radio Button just because the text corresponding to Radio Button receives focus.
So my question is:
Is there any way I can make TextView non-focusable but receive Long Click events?
Is there any way I can pass the focus down to the parent layout?
Any other way you can suggest?
(PS: Please do not say what I am doing is right or wrong. It's just a feasibility test for what I am trying to achieve.)
A view does have the attributes "focusable" and "longClickable". Have you tried a combination of these?

Categories

Resources