在我的应用程序中,我试图从XML文件中存储在网络中形成网格视图。在网络中与图像形成gridview的问题
以下是我的代码
grid = (GridView)findViewById(R.id.gridView1);
imageXMLfn();
grid.setAdapter(new ImageAdapter(this));
private void imageXMLfn()
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setIgnoringComments(true);
factory.setCoalescing(true);
factory.setNamespaceAware(false);
factory.setValidating(false);
DocumentBuilder parser = factory.newDocumentBuilder();
URL url = new URL(UserManual.IMAGE_URL);
Log.e("ViewImage3",""+UserManual.IMAGE_URL);
Document document= parser.parse(new InputSource(url.openStream()));
NodeList sections = document.getElementsByTagName("application");
numSections = sections.getLength();
for (int i = 0; i < numSections; i++)
{
Element section = (Element) sections.item(i);
if(section.hasChildNodes()==true)
{
NodeList section1=section.getChildNodes();
for(int j=0;j<section1.getLength();j++)
{
if(section1.item(j).hasChildNodes()==true)
{
for(int k=0;k<section1.item(j).getChildNodes().getLength();k++)
{
xmlvalue=String.valueOf(section1.item(j).getChildNodes().item(k).getNodeValue()).trim();
arl.add(xmlvalue);
}
}
}
}
}
}
catch(Exception e)
{
System.out.println(e);
Log.e("ViewImage Error1",e.getMessage());
}
Iterator<String> itr = arl.listIterator();
int z=0,x=0,increment=0;
while (itr.hasNext())
{
id = itr.next();
img = img+id;
z++;
}
}
public class ImageAdapter extends BaseAdapter
{
private Context myContext;
private String[] myRemoteImages = {id};
public ImageAdapter(Context c)
{
this.myContext = c;
}
}
无论我得到只有第一个图像存储在网址或其他我没有得到任何其他图像
以下是从我试图链接得到的图像
http://94.23.207.167/websiteIphone/Admin/XML/Santa.xml
你是什么意思获得图像?它出错了哪里?你有例外吗?你能读取xml文件中的所有图像吗?适配器中是否有可用的图像? gridview是否可见,是否正确构建?你需要更具体地了解什么是错误的,它做了什么,你期望它做什么和工作。 – Ishtar 2011-06-07 09:02:04
我可以读取所有图像的名称。在我的gridView中,我只获取了xml文件中的最后一张图片。我无法查看xml文件中的所有图像。 – 2011-06-07 09:36:49
那么适配器呢?它是否包含图像? – Ishtar 2011-06-07 09:40:52