2012-02-17 3 views
0

リストビューの行にハイパーリンク(ハイパーリンクとして形式化されている)を表示しようとしていますが、運が足りません。Android:ListFragmentのハイパーリンクリストビューの行

public void setNews(){   

     TextView textcontent = (TextView) news_row.findViewById(android.R.id.text2); 
     textcontent.setMovementMethod(LinkMovementMethod.getInstance()); 

     String[] matrix = {"_id", "title", "content", "date"}; 
     String[] columns = {"title", "content", "date"}; 
     int[] layouts = {android.R.id.text1,android.R.id.text2, R.id.text3}; 

     MatrixCursor cursor = new MatrixCursor(matrix); 
     for(int i = 0 ; i < straNewsTitle.length; i++) { 
      cursor.addRow(new Object[] {i, straNewsTitle[i], Html.fromHtml(straNewsContent[i]), straNewsDate[i] }); 
     } 
     SimpleCursorAdapter a = new SimpleCursorAdapter(fa, R.layout.news_row, cursor, columns, layouts);   
     setListAdapter(a); 
} 

straNewsContentは、本文テキストを保持している:まず、私は、行の人気そしてonActivityCreateでsetNewsを呼び出し、ハイパーリンクでのTextViewを探し、後に

news_row = (LinearLayout) inflater.inflate(R.layout.news_row,null); 

ためonCreateViewでクラス変数にnews_rowビューを膨らませますHTMLハイパーリンクタグを含むかもしれないニュース項目のために。マイnews_rowレイアウト:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffefe5" android:orientation="vertical" android:paddingLeft="15px" android:paddingRight="15px" android:paddingBottom="5px" android:paddingTop="5px"> 
<TextView 
    android:id="@android:id/text1" 
    android:gravity="top" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#666666" 
    android:textSize="20dp" 
    android:background="#ffefe5" 
    android:textStyle="bold" 
/> 
<TextView 
    android:id="@android:id/text2" 
    android:gravity="bottom" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@android:id/text1" 
    android:textColor="#666666" 
    android:textSize="15dp" 
    android:background="#ffefe5" 
    android:autoLink="web|email" 
/> 
<TextView 
    android:id="@+id/text3" 
    android:gravity="bottom" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@android:id/text1" 
    android:textColor="#666666" 
    android:textSize="12dp" 
    android:background="#ffefe5" 
/> 
</LinearLayout> 

アンドロイド:オートリンク=「ウェブ|電子メールには、」URLをフォーマットされますが、HTMLタグがレンダリングされていない文字列の素晴らしい作品。どんな助けも素晴らしいだろう。

答えて

0

はそれを考え出しました。私自身のBaseAdapterを実装し、getView()で変更を加えなければなりませんでした。

0

Html.fromHtml(String source)を試してください。これは、HTMLスニペットを入力として受け取り、TextViewを配置するためにフォーマットされた文字列を出力します。

は例えば、ここでApiDemosアプリからの抜粋です:

TextView t3 = (TextView) findViewById(R.id.text3); 
    t3.setText(
    Html.fromHtml(
     "<b>text3:</b> Text with a " + 
     "<a href=\"http://www.google.com\">link</a> " + 
     "created in the Java source code using HTML.")); 
    t3.setMovementMethod(LinkMovementMethod.getInstance()); 
+0

私は既にHTML.fromHTMLを使用しています。 – Scott