我正在寫有文字的ListView控件的應用程序。在每一行中都有文字和鏈接的組合。我添加了一個OnItemLongClickListener到列表中,變成可點擊的鏈接與LongClick TextView的,可點擊的鏈接
my_text.setMovementMethod(LinkMovementMethod.getInstance());
的問題是,如果我能夠點擊鏈接,我不能讓TextView的註冊LongClick。
我已經嘗試了不同的方法,使可點擊這樣的鏈接作爲
android:autoLink="web
但是,這並不使鏈接點擊。
我的問題是:是否有不同的方式,我應該設置LongClickListener,或不同的方式來使鏈接可點擊?
有沒有其他人遇到過類似的問題?
我要指出的是,現在的OnItemLongClickListener使得鏈接註冊LongClicks但這會導致一個問題,當一個TextView可是沒有一個鏈接或用戶嘗試到別處longClick在視圖中(除了鏈接)
代碼: 編程方式哄擡的RelativeLayout包含列表視圖,並將其添加到視圖的鰭狀肢:
的RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/my_list"
style="@style/listViewSimple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f9f9f9"
android:cacheColorHint="#00000000"
android:divider="#ccc"
android:dividerHeight="1px"
android:fadingEdge="none"
android:fadingEdgeLength="30dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:persistentDrawingCache="none" >
</ListView>
</RelativeLayout>
添加一切編程:
RelativeLayout list = (RelativeLayout) LayoutInflater.from(MyActivity.this).inflate(R.layout.my_list_layout, null);
vf.addView(list);
ListView lv = (ListView) list.findViewById(R.id.my_list);
lv.setOnItemLongClickListener(listLongListener);
製作(adapte的getView())鏈接點擊:
my_tv.setText(Html.fromHtml(formatted_text)));
my_tv.setLinkTextColor(linkColor);
my_tv.setMovementMethod(LinkMovementMethod.getInstance());
這使得可點擊的鏈接,但似乎消耗的所有點擊他們得到TextView的面前。我試圖添加一個返回false的longClickListener,但似乎沒有任何影響。
我的臨時解決方法是將itemLongClickListener和onItemClickListener設置爲listItem,並僅顯示onListItemClick中可點擊文本的對話框。這可以工作,但增加了一個額外的點擊用戶與文本交互
你能告訴我你需要什麼longclick嗎?我點擊鏈接會在webview中打開它。你是否有要求單擊列表中的項目時,會打開另一個活動及其詳細信息? – Shubhayu 2012-03-17 02:26:46
我用的是長按則可打開選項對話框,可將他們帶到不同的活動,這取決於被點擊的listItem用戶。 – ByteMe 2012-03-20 02:48:00
你可以添加代碼,你現在把OnItemLongClickListener()和你讓鏈接可點擊的部分嗎?還提供了包含你的列表和包含你的列表項目的XML。 – Shubhayu 2012-03-20 05:56:51