在ListView的Andr​​oid显示HTMLAndr、ListView、HTML、oid

2023-09-04 09:25:45 作者:五行缺真爱

抱歉,如果这是有目共睹的其他人,但我有一个小很难理解怎么我的列表视图内显示HTML。

Sorry if this is obvious to everyone else but I am having a minor difficulty understanding how to display html inside my listview.

我的列表视图声明。

ListView lv1 = (ListView) findViewById(R.id.ListView01);

我来填充它(未显示),然后将我的列表视图这里的ArrayAdapter。

I populate it (not shown) then set my listview here with an ArrayAdapter.

lv1.setAdapter(new ArrayAdapter<String>(SearchByFood.this, R.layout.new_list_view, foods));

再往下我创造,我想有粗体标签字符串的一个新的数组,然后我这个新的数组(称为arr_sort)添加到一个ArrayAdapter insdie一个onTextChanged()方法。

Further down I create a new array of strings that I want to have bold tags in. I then add this new array (called arr_sort) to the arrayadapter insdie a onTextChanged() method.

lv1.setAdapter(new ArrayAdapter<String>(SearchByFood.this, R.layout.new_list_view, arr_sort));

所以,现在我的新字符串数组有&LT; B>标记它。如何让我的列表视图显示粗体文字?

So now that my new Array of Strings has < b > tags in it. How do I make my listview display the bold text?

下面是我的new_list_view

Here is my new_list_view

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/grey2"
    android:textSize="20sp"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="40dip"
/> 

这是我的主要的布局我的ListView的一部分。

And here is my ListView part in my main layout.

        <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_corners_green"
        android:cacheColorHint="#00000000"
        android:divider="@color/green6"
        android:dividerHeight="1px"
        android:fastScrollEnabled="true" >
    </ListView>

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

推荐答案

覆盖适配器的getItem方法并执行以下操作:

override getItem method of the Adapter and do the following:

ArrayAdapter<String> adapter= ArrayAdapter<String>(SearchByFood.this, R.layout.new_list_view, arr_sort){
     public Object getItem(int position)
     {
          return Html.fromHtml(arr_sort.get(position));
     }
};