我想通过SAX Parser解析它并通过url加载图像并将其传递给下一个要显示的活动。但是,如果有任何人可以帮助我或给我一些可重复使用的代码,那么我没有这样做,那么我将不胜感激。这是我的xml文件。这是我解析的数据类和适配器类不要向arraylist添加项目。请帮助。
PARSEDDATA CLASS
公共类ParseData扩展了DefaultHandler { boolean title,cost,pubDate,link = false;
private String temp = "";
ArrayList<String> arrtitle = new ArrayList<String>();
ArrayList<String> arrcost = new ArrayList<String>();
ArrayList<String> arrpubDate = new ArrayList<String>();
ArrayList<String> arrlink = new ArrayList<String>();
//---------START ELEMENT----------//
@Override
public void startElement(String uri , String localName , String qName , Attributes attributes) throws SAXException
{
super.startElement(uri, localName, qName, attributes);
if(localName.equalsIgnoreCase("title"))
{
title = true;
}else if(localName.equalsIgnoreCase("cost"))
{
cost = true;
}else if(localName.equalsIgnoreCase("pubDate"))
{
pubDate = true;
}else if(localName.equalsIgnoreCase("link"))
{
link = true;
}
}
//--------END ELEMENT----------//
@Override
public void endElement(String uri , String localName , String qName) throws SAXException
{
super.endElement(uri, localName, qName);
if(localName.equalsIgnoreCase("title"))
{
title = false;
}else if(localName.equalsIgnoreCase("cost"))
{
cost = false;
}else if(localName.equalsIgnoreCase("pubDate"))
{
pubDate = false;
}else if(localName.equalsIgnoreCase("link"))
link = false;
}
@Override
public void characters(char[] ch, int start, int length)throws SAXException
{
super.characters(ch, start, length);
if(title)
{
}
if(cost)
{
}
if(pubDate)
{
}
if(link)
{
}
}
}
BINDADAPTER CLASS
public class BindDataAdapter扩展了BaseAdapter {
ArrayList<String> title;
ArrayList<String> cost;
ArrayList<String> pubDate;
LayoutInflater inflater;
//---------DEFAULT CONSTRUCTOR-----------//
public BindDataAdapter()
{
}
//-------PARAMETERIZED CONSTRUCTOR------//
public BindDataAdapter(Activity activity , ArrayList<String> title , ArrayList<String> cost , ArrayList<String> pubDate)
{
this.title = title;
this.cost = cost;
this.pubDate = pubDate;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return title.size();
}
@Override
public Object getItem(int position)
{
return position;
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position , View convertView , ViewGroup parent)
{
if(convertView == null)
{
convertView = inflater.inflate(R.layout.list_row , null);
}
TextView textViewtitle = (TextView) convertView.findViewById(R.id.type);
TextView textViewcost = (TextView) convertView.findViewById(R.id.cost);
TextView textViewdate = (TextView) convertView.findViewById(R.id.date);
return convertView;
}
}
答案 0 :(得分:0)
使用您用于解析数据的相同代码和For image,添加额外的变量和参数作为explaine in this link并使用ImageLoader类在listView中加载图像。
您也可以参考this,Android lazy image loader example和Loading Remote Images in a ListView on Android链接以供参考。
随意发表评论。