在我的應用程序中,我試圖從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