android:html列表视图在string.xml文件中不起作用

时间:2013-09-16 15:36:53

标签: android textview

我必须在片段中插入一个列表(不是android列表视图,而是简单的html列表)。布局文件“about.xml”页面只有一个动态聚类的textview,从string.xml文件中获取数据。 string.xml中的声明如下:

<string name="AboutThisApp"><![CDATA[

<div>
    <p>here is the list of functions: </p>
</div>

<ul>
    <li> Sportsmanship</li>
    <li> Participation</li>
    <li> Safety/Risk Minimization</li>
    <li> Sound Traditions of the Sport</li>
    <li> Support for USA Footvall\'s Mission</li>
    <li> Balance Between Offense and Defence</li>
</ul>

]]></string>

此数据正在布局文件夹中的textview中访问,如下所示(文件为“about.xml”):

<TextView
            android:id="@+id/textViewAbout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="16dp"
            android:textColor="@color/white"
            android:textSize="16dp"
            customText:textcustomFont="fonts/montserrat-r.ttf" />

访问java文件中数据的对象如下:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.usafootball.rulesapp.R;
import com.usafootball.rulesapp.customfont.TextViewPlus;

public class AboutThisAppFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View mView = inflater.inflate(R.layout.about,
                container, false);
        TextViewPlus textViewPlus = (TextViewPlus) mView.findViewById(R.id.textViewAboutUSAF);
        textViewPlus.setText(Html.fromHtml(getString(R.string.AboutThisApp)));

        return mView;
    }

}

为了更清楚地显示数据,但它以段落的形式显示为NOT LIST。有任何建议怎么做......

2 个答案:

答案 0 :(得分:2)

<ul>不支持AFAIK <li>TextView标记,这就是它无效的原因。请在此处查看支持的代码列表:HTML Tags Supported By TextView

答案 1 :(得分:0)

1. TextView not support all html tag.
2. Use WebView rather than TextView.

**layoutname.xml**
<WebView
   android:id="@+id/webview"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"/>

**string.xml**
<string name="AboutThisApp">&lt;div>
    &lt;p>here is the list of functions: &lt;/p>
&lt;/div>

&lt;ul>
    &lt;li> Sportsmanship&lt;/li>
    &lt;li> Participation&lt;/li>
    &lt;li> Safety/Risk Minimization&lt;/li>
    &lt;li> Sound Traditions of the Sport&lt;/li>
    &lt;li> Support for USA Footvall\'s Mission&lt;/li>
    &lt;li> Balance Between Offense and Defence&lt;/li>
    &lt;/ul>

</string>

**activity**
 private WebView webview;
 // write below code in onCreate()
 webview = (WebView) findViewById(R.id.webview);
 webview.loadData(getString(R.string.AboutThisApp),"text/html","utf-8");