我正在使用json解析,我从服务器得到响应,在我的响应中它包含一些html标签,它显示在我的listview中..我在listview中使用imageview和textview ..如何删除html标签?
回复
[
{
"title_tag":"business",
"description":"<p>\r\n\t<strong>Lorem Ipsum<\/strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\r\n",
"image":"1.jpg"
}
]
Myadapter
public class CustomAdapterAdvertisement extends BaseAdapter{
private Context context;
private ArrayList<HashMap<String,String>> listData;
private AQuery aQuery;
private static final String ADD_NAME="title_tag";
private static final String ADD_DESC="description";
private static final String ADD_IMAGE="image";
public CustomAdapterAdvertisement(Context context,ArrayList<HashMap<String,String>> listData) {
this.context = context;
this.listData=listData;
aQuery = new AQuery(this.context);
}
@Override
public int getCount() {
return listData.size();
}
@Override
public Object getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public String stripHtml(String html) {
return Html.fromHtml(html).toString();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.advertisement_detail, null);
holder.propic = (ImageView) convertView.findViewById(R.id.advertisement_img);
holder.txtproname = (TextView) convertView.findViewById(R.id.txtnameadvertisement);
// holder.txtproid = (TextView) convertView.findViewById(R.id.txtproidsearch);
holder.txtprofilecast = (TextView) convertView.findViewById(R.id.txtadvertisementdescription);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.txtproname.setText(listData.get(position).get(ADD_NAME));
//holder.txtproid.setText(listData.get(position).get(TAG_PROFILE));
holder.txtprofilecast.setText(listData.get(position).get(ADD_DESC));
holder.txtprofilecast.setText(Html.fromHtml("description").toString());
aQuery.id(holder.propic).image(listData.get(position).get(ADD_IMAGE),true,true,0,R.drawable.ic_launcher);
// image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image
return convertView;
}
class ViewHolder{
ImageView propic;
TextView txtproname;
// TextView txtproid;
TextView txtprofilecast;
}
}
答案 0 :(得分:3)
如何从listview中删除html标签?
与提供的description
关键文字一样,Html.fromHtml支持所有html标记。
要在TextView中显示html格式的文本,请使用Html.fromHtml
:
String strDes=Html.fromHtml(description).toString();
答案 1 :(得分:1)
请找到以下解决方案
您可以尝试以下操作,在包中创建类并将其命名为“Util”
public class Util{
public static String stripHtml(String html)
{
//html = "<p sapn = 'div'>hhhhhhhhh<p> Hello World </p></span>";
while(html.contains("<"))
html = html.replace(html.substring(html.indexOf("<"),html.indexOf(">")+1),"");
return html;//will return hhhhhhhh Hello World
}
}
此方法将搜索以“&lt;”开头的任何文本并以“&gt;”结尾它将取代它。
然后您可以在任何地方使用该方法
String myNewStringWithoutHTML = Util.stripHtml(STRING);
希望以上解决方案能为您提供帮助。
请告诉我是否需要更多帮助。我在这一方面也是如此。
答案 2 :(得分:0)
var book = {
"title_tag":"business",
"description":"<p>\r\n\t<strong>Lorem Ipsum<\/strong> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\r\n",
"image":"1.jpg"
}
$(function(){
$('body').append("<div class='text'>"+book.description+"</div>");
alert($('.text').text());
$('.text').hide();
})