Android Display HTML in a ListView

后端 未结 9 2073
情话喂你
情话喂你 2020-12-16 05:54

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

My list view is declared.

9条回答
  •  -上瘾入骨i
    2020-12-16 06:04

    If you are using a SimpleAdapter, here is the code that enables HTML on a TextView.

    adapter.setViewBinder(new SimpleAdapter.ViewBinder() {  
        public boolean setViewValue(View view, Object data, String textRepresentation) {  
            if (data instanceof Spanned && view instanceof TextView) {  
                ((TextView) view).setText((Spanned) data);  
            } else {  
                ((TextView) view).setText(Html.fromHtml(String.valueOf(data))); 
            }  
            return true;  
            }  
        }  
    ); 
    

    Ref: [Link] (http://android.jreactor.com/2012/07/17/simpleadapter-spanned-html-fromhtml/)

提交回复
热议问题