Links and text in listview item

被刻印的时光 ゝ 提交于 2019-12-10 16:17:53

问题


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! :)


回答1:


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


来源:https://stackoverflow.com/questions/9959818/links-and-text-in-listview-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!