如何从列表视图中删除 html 标签?
How to remove html tags from listview?
我正在使用 json 解析,我正在从服务器获得响应,在我的响应中它包含一些 html 标签,它显示在我的列表视图中。我正在使用 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"
}
]
我的适配器
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;
}
}
请按以下方式寻找解决方法
您可以尝试以下操作,在您的包中创建 class 并将其命名为 "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
}
}
此方法将搜索以“<”开头并以“>”结尾的任何文本并将替换它。
然后你可以在任何地方使用这个方法
String myNewStringWithoutHTML = Util.stripHtml(STRING);
希望以上解决方案对您有所帮助。
让我知道是否需要我这边的更多帮助。
How to remove html tags from listview?
如所提供的 description
关键文本,Html.fromHtml 支持所有 html 标签。
要在 TextView 中显示 html 格式的文本,请使用 Html.fromHtml
:
String strDes=Html.fromHtml(description).toString();
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();
})
我正在使用 json 解析,我正在从服务器获得响应,在我的响应中它包含一些 html 标签,它显示在我的列表视图中。我正在使用 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"
}
]
我的适配器
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;
}
}
请按以下方式寻找解决方法
您可以尝试以下操作,在您的包中创建 class 并将其命名为 "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
}
}
此方法将搜索以“<”开头并以“>”结尾的任何文本并将替换它。
然后你可以在任何地方使用这个方法
String myNewStringWithoutHTML = Util.stripHtml(STRING);
希望以上解决方案对您有所帮助。
让我知道是否需要我这边的更多帮助。
How to remove html tags from listview?
如所提供的 description
关键文本,Html.fromHtml 支持所有 html 标签。
要在 TextView 中显示 html 格式的文本,请使用 Html.fromHtml
:
String strDes=Html.fromHtml(description).toString();
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();
})