TextView autoLink 問題請教

50 views
Skip to first unread message

ericsk

unread,
Feb 26, 2009, 12:34:22 PM2/26/09
to Android TW Developer
Dear all,

最近在開發 android app 碰到一個 UI design 上的小困難,我大致描述一下我的問題:

我有一個 ListView (X), 然後是自己實作了一個 ListAdapter (Y), 在 Y 中有 ImageView 及
TextView
TextView 可以設 autoLink="web" 讓文字中出現超連結的部份自動處理開啟 browser 的動作。

但是這樣一來,X 的每一個 item 就不會觸發 onItemClick (當然 onItemLongClick 也不行)。
我有找到一個討論串:
http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a/9f9919a4b604c104?lnk=gst&q=clickable+focusable#9f9919a4b604c104

上面有提供一個解決方案,我照著做了之後的確是可以開啟 autoLink 也會觸發 onItemClick,
但是「一定要 click item 中『非 TextView』 的部份才會觸發 itemClick」,點了 TextView 的區域(就算它上
面沒有 link)則無效。

不知道有沒有人碰過這個問題而有解決之道的呢?

以下附上 Y 的 layout XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ImageView android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView android:id="@+id/msg"
android:layout_gravity="top"
android:layout_width="0dip"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColorLink="#7cecff"
android:textColor="#fafafa"/>

</LinearLayout>

Reply all
Reply to author
Forward
0 new messages