如何使动态文本加粗有标签< B> < / B>在列表视图? [英] How to make dynamic text bold having tag <b> </b> in listview?

查看:173
本文介绍了如何使动态文本加粗有标签< B> < / B>在列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,我解析 JSON 数据和修正的结果列表视图的应用程序。在 JSON 响应我得到以下响应:

I'm developing an application in which I'm parsing JSON data and fixing the result in the listview. In JSON response I'm getting the following response:

{
"searchdata": {
    "webresult": [
        {
            "title": "<b>Android</b>",
            "desc": "Discover a new flavor of Jelly Bean <b>Android</b> 4.2 introduces a completely new camera experience, a new form of typing that helps you power ...",
            "link": "http://www.android.com/"
        },
        {
            "title": "<b>Android</b> (operating system) - Wikipedia, the free encyclopedia",
            "desc": "<b>Android</b> is a Linux -based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by <b>Android</b> ...",
            "link": "http://en.wikipedia.org/wiki/Android_(mobile_phone_platform)"
        }
    ]
}

}

标题正如你所看到的的Andr​​oid 标签内都来了。我想使它大胆。

In title as you can see Android tags are coming. I want to make it bold.

下面是我在做什么固定在ListView的响应。

Here is what I'm doing for fixing those response in the listview.

try {
    HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet("MY API");
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet, rHandler);

JSONObject rootObj = new JSONObject(data);

JSONObject jSearchData = rootObj.getJSONObject("searchdata");

JSONArray jsonArray = jSearchData.getJSONArray("webresult");

for (int i = 0; i < jsonArray.length(); i++) {

    JSONObject objJson = jsonArray.getJSONObject(i);

    String title = objJson.getString("title");
    String desc = objJson.getString("desc");
    String link = objJson.getString("link");

    HashMap<String, String> map = new HashMap<String, String>();

    map.put("title", title);
    map.put("description", desc);
    map.put("link", link);

    searchList.add(map);
    }

} catch (Exception e) {
       System.out.println("Exception: " + e);
}

通过上面的code我得到的响应,并将其存储到的Hashmap 。之后,我使用自定义布局显示的内容。继code可以帮助我获得固定布局的值。

By the above code I'm getting the response and storing them into Hashmap. After that I'm using custom layout for displaying the content. Following code helps me getting the values fixed in the layout.

ListAdapter adapter = new SimpleAdapter(getApplicationContext(),
searchList, R.layout.list_row, new String[] { "title","description", "link" }, new int[] { R.id.title,R.id.desc, R.id.url });

setListAdapter(adapter);

下面是什么样子时,所有的事情进展顺利。

Here, is what it looks like when all things go well.

正如你所看到的 HTML 标签来了。能否请人建议如何使 HTML 粗体标签内的文本加粗?

As you can see the html tags are coming. Can please anyone suggest how to make the text bold inside the html bold tags?

任何帮助将是该AP preciated。

Any help will be appreciated for this.

推荐答案

您可以使用的 SimpleAdapter.ViewBinder 并设置了 HTML 值到的TextView 而不是纯文本。

You can use SimpleAdapter.ViewBinder and set a html value to the TextView instead of plain text.

SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), searchList, R.layout.list_row, new String[] { "title","description", "link" }, new int[] { R.id.title,R.id.desc, R.id.url });
SimpleAdapter.ViewBinder binder = new SimpleAdapter.ViewBinder() {
    @Override
    public boolean setViewValue(View view, Object object, String value) {
        if (view instanceof TextView) {
            ((TextView) view).setText(Html.fromHtml(value));
            return true;
        }

        return false;
    }
};

adapter.setViewBinder(binder);
setListAdapter(adapter);

这篇关于如何使动态文本加粗有标签&lt; B&GT; &LT; / B&GT;在列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆