Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Links in Android List View

I have a custom listview in android, with each item consisting of several text views. One of the text views contains HTML text, some of which contains <a> tags. I am using the HTML.fromHTML() method to translate this into a String readable by the textView, but the links are not clickable. If I enable them to have focus, then the list items are no longer clickable and the links still do not work.

So how do I make the links clickable, and keep the normal click functionality if a list item is clicked anywhere other than on a link?

EDIT: My code:

    if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.email_list_item, null);
    }


    TextView contentView = (TextView) convertView
            .findViewById(R.id.content);

    Email e = items.get(position);

    CharSequence content = "";
    if (e.getContent() != null) {
        content = Html.fromHtml(e.getContent());
    }

    contentView.setText(content);
    return convertView;
like image 834
leedsunited92 Avatar asked Jun 28 '26 22:06

leedsunited92


1 Answers

You need to set AutoLinkMask

textcontent.setText(Html.fromHtml(text.get_text()));
textcontent.setAutoLinkMask(Linkify.WEB_URLS);
like image 153
kosa Avatar answered Jun 30 '26 11:06

kosa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!