0

我正在尝试从 url 中显示一个字段,但该字段仅显示在特殊字符出现的位置。例如,数据是:

社会公益峰会是关于什么的?</strong><p> <p>全球社会公益峰会旨在将社会企业和慈善机构与技术和社交媒体公司聚集在一起,探讨如何解决世界上的一些问题最大的困难。

但是当显示时,它只显示:

社会公益峰会是关于什么的?

我尝试使用 SpannableStringBuilder 但它仍然不起作用。这是示例代码:

public class AndroidXMLParsingActivity extends ListActivity {

    static final String URL = "http://api.eventful.com/rest/events/search?app_key=42t54cX7RbrDFczc&location=singapore";
    // XML node keys
    static final String KEY_EVENT = "event"; // parent node
    static final String KEY_TITLE = "title";
    static final String KEY_URL = "url";
    static final String KEY_DESC = "description";
    static final String KEY_START_TIME = "start_time";
    static final String KEY_STOP_TIME = "stop_time";
    static final String KEY_VENUE_NAME = "venue_name";
    static final String KEY_COUNTRY_NAME = "country_name";

    String regex = "</{0,1}.+?>";
    String replacement = "";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_EVENT);
        // looping through all item nodes <item>
        for (int i = 0; i < nl.getLength(); i++) {
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);
            // adding each child node to HashMap key => value
            map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
            map.put(KEY_URL, parser.getValue(e, KEY_URL));
            map.put(KEY_DESC, "Description: " + parser.getValue(e, KEY_DESC));
            map.put(KEY_START_TIME, parser.getValue(e, KEY_START_TIME));
            map.put(KEY_STOP_TIME, parser.getValue(e, KEY_STOP_TIME));
            map.put(KEY_VENUE_NAME, parser.getValue(e, KEY_VENUE_NAME));
            map.put(KEY_COUNTRY_NAME, parser.getValue(e, KEY_COUNTRY_NAME));
            // adding HashList to ArrayList

            menuItems.add(map);


        }



        // Adding menuItems to ListView
        ListAdapter adapter = new SimpleAdapter(this, menuItems,
                R.layout.list_item, new String[] { KEY_TITLE,  KEY_COUNTRY_NAME,
                        KEY_VENUE_NAME, KEY_START_TIME }, new int[] {
                        R.id.title, R.id.countryName, R.id.venueName,
                        R.id.startTime });

        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(KEY_DESC);

        TextView contentView = (TextView) findViewById(R.id.description);
        contentView.setText(stringBuilder);
4

1 回答 1

0

尝试使用 HTML.fromHTML(String source) 方法:

public static Spaned fromHtml (String source)

提供你上面提到的字符串..

于 2013-08-01T06:16:43.027 回答