我试图在列表视图行中显示超链接(格式化为超链接),但没有任何运气。首先,我膨胀news_row视图类变量在onCreateView供以后Android:超链接ListFragment ListView行
news_row = (LinearLayout) inflater.inflate(R.layout.news_row,null);
我称之为onActivityCreate setNews,然后寻找有超链接,然后流行行的TextView的:
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持有正文对于可能包含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>
机器人:自动链接=“网页|电子邮件”的伟大工程被格式化网址,但HTML标签不被渲染的字符串。任何帮助都是极好的。
我已经在使用HTML.fromHTML。 – Scott 2012-02-18 00:39:14