[英]how to set clickable links in a text view of an expandable list view in android?
在我的Android應用程序中我使用可擴展列表視圖來顯示一些文本。這些文本包含網址,所以我想設置可點擊這些URL轉到請求的網頁。我已將以下xml行添加到我的組布局以顯示鏈接在我的可擴展列表視圖上。
android:autoLink="web"
它顯示藍色的URL,但可擴展列表不擴展,當我點擊鏈接時,它會給出以下異常。我怎么能解決這個問題?
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
點擊父子視圖后顯示其內容。 所以我想做的是設置url clickable顯示在parent.while展開並折疊可擴展列表。
我這樣做但它也沒有用。
expList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Linkify.addLinks(groupNameContent, Linkify.WEB_URLS);
Log.e("setOnGroupClickListener", "tested");
return true;
}
});
父只是一個文本視圖,當用戶點擊它展開的父對象並顯示包含父:parent xml的其他詳細信息的子對象時:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textSize="11dp"
android:textStyle="normal"
/>
當您從外部活動啟動新意圖時,需要使用啟動活動用戶設置標志
intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK)
我將給你一個不同的場景,它將實現相同的目標。 當您單擊ExpandableListView父項時,它將顯示子項。 然后,通過單擊相同的父項將折疊父項並詢問用戶是否要轉到父文本中的任何鏈接。 以下圖片將向您展示我將在這里做什么。 可擴展列表視圖(圖1)
單擊父項后可展開的列表視圖
為用戶提供選項以選擇轉到鏈接或返回正常界面的選項
OnGroupClickListener
但我使用的是OnGroupCollapseListener
。 getGroup(groupPosition)
來做到這getGroup(groupPosition)
嘗試使用linkify ..示例在這里 ..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.