简体   繁体   中英

Clickable item with clickable urls in ListView

I have custom ListView item with ImageView and TextView. TextView contains HTML string with urls and some regular text. Im my adapter I have code similar to

tv.setText(Html.fromHtml("<a href='http://google.com'>google</a>")); tv.setMovementMethod(LinkMovementMethod.getInstance());

and this works great but onListItemClick isn't executed when I click on item outside url, whole item looks like inactive.

When I click on url I want to fire default action form urls and when I click on regular text or on ImageView I want to execute onListItemClick is it possible?

Second question, is it possible to start activity using <a href="...">start some activity</a> ?

You can't make an intent form an anchor.

It's ok and recommended that you use onListItemClick (it saves you a lot of work), and if you want to open the link in the browser (without using a webview ) you can use this an intent, this is an example:

Intent myIntent = new Intent(Intent.ACTION_VIEW,ContentURI.create("http://www.google.com"));
startActivity(myIntent);

Hope this helps.

You need to specify a callback for each of the views that you wish to select. I believe you have three different items: The Listview object, which contains a TextView and an ImageView .

If you would like to have different behavior for each different piece, you need to create a callback for each different piece. You can set a callback in the XML declaration of the view by setting

android:onClick="myCallback"

http://developer.android.com/reference/android/view/View.html#attr_android:onClick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM