2013-06-04 47 views
0

由於某些原因,我使textviews可點擊並將自動鏈接設置爲網頁後,它仍然無法打開瀏覽器。我是否需要使用事件偵聽器,然後如此處理?或者我忽略了一些簡單的東西?我會通過張貼TextView的XML代碼開始:小部件textview中的可點擊超鏈接

<TextView 
     android:id="@+id/textView6" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.11" 
     android:autoLink="web" 
     android:background="@drawable/back" 
     android:clickable="true" 
     android:gravity="center" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 
+0

http://android-developers.blogspot.in/2008/03/linkify-your-text.html。檢查鏈接 – Raghunandan

+0

不幸的是,小部件必須使用相當有限的remoteViews。它不能使用findViewByID –

+0

你可以嘗試點擊跨度。不知道它會適用於您的要求 – Raghunandan

回答

0

我不得不使用一個onclick事件來處理瀏覽器發射。我還在機器人編程,所以我從here得到信息的完整業餘:

// Register an onClickListener 
      Intent broswerIntent = new Intent(Intent.ACTION_VIEW, 
        Uri.parse("http://www.cnn.com")); 
      broswerIntent.addCategory(Intent.CATEGORY_BROWSABLE); 
      broswerIntent.setComponent(new ComponentName("com.android.browser", 

      "com.android.browser.BrowserActivity")); 
      PendingIntent pendingIntent = PendingIntent.getActivity(
        getApplicationContext(), 0, broswerIntent, 0); 
1

此代碼是寫年前,但我認爲它應該工作:

TextView result_view = new TextView(this); 
result_view.setText(Html.fromHtml("<a href=" + linkUrl + ">"+ linkTitle + "</a>")); 
result_view.setMovementMethod(LinkMovementMethod.getInstance()); 
+0

不幸的是,這隻適用於活動。 RemoteViews無法訪問setMovementMethod方法。這可能會寫成不可能的,直到更新或某事。 –

+0

我沒有使用RemoteView的經驗,但也許你應該在這種情況下使用Intent.ACTION_VIEW? – Viacheslav

0

添加以下行。

final TextView input = new TextView(this); 
      alert.setView(input); 
      input.setText(Html.fromHtml("www.google.com")); // you can pass your strings over there. 
      Linkify.addLinks(input, Linkify.ALL); 
      alert.setMessage("Test"); 

希望這可以幫助你。