在我的应用程序中,当我点击一个网址时,它从该文件返回一个xml文件我得到一些图像。通过sax解析器,我得到图像的no和存储图像的url。现在我想在网格视图中显示所有图像。但对我来说,只有xml文件中的最后一个图像是以网格格式单独查看的。以下是我的代码
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(UserManual.IMGDATA));
xr.setContentHandler(forlistmyhandler);
xr.parse(is);
sitesList = forlistmyhandler.getSearch();
searchdata = forlistmyhandler.getSearchdata();
Q = sitesList.getSearchdata().size();
for(int k=0;k<sitesList.getSearchdata().size();k++)
{
Log.e("MyXMLHandler", "000000000 Created");
Searchdata chap = sitesList.getSearchdata().get(k);
id = chap.getId();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ID", id );
grid.setAdapter(new ImageAdapter(this));
Log.e("id tag",""+id);
}
public class ImageAdapter extends BaseAdapter
{
private Context myContext;
private String[] myRemoteImages = {id};
public ImageAdapter(Context c)
{
this.myContext = c;
}
}
请帮我解决我的问题
答案 0 :(得分:0)
在这些情况下,而不是使用Hashmap尝试使用String []。在ArrayList中添加值,然后转换为String Array。
将String []传递给适配器并加载图像并显示。
在这些循环代码中:
ArrayList<String> images = new ArrayList<String>();
String[] VALUE_images;
for(int k=0;k<sitesList.getSearchdata().size();k++)
{
Log.e("MyXMLHandler", "000000000 Created");
Searchdata chap = sitesList.getSearchdata().get(k);
id = chap.getId();
images.add(id );
}
int img=-1;
VALUE_images= new String[images.size()];
Iterator<String> it = images.iterator();
while (it.hasNext()) {
img++;
VALUE_images[dealid] = it.next().toString();
}
grid.setAdapter(new ImageAdapter(this,VALUE_images));
public class ImageAdapter extends BaseAdapter
{
private Context myContext;
private String[] myRemoteImages = {id};
public ImageAdapter(Context c,String[] value1)
{
this.myContext = c;
VAL1 = value1;
}
// as usual code follows