想要在android中的gridView中显示所有图像

时间:2014-09-26 10:37:20

标签: android

<?xml version="1.0" encoding="UTF-8"?>
<Location>
   <attraction>
      <ID>291</ID>
      <Title>Great Eastern Hotel</Title>
      <FeaturedImage>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Lighthouse.jpg</FeaturedImage>
      <FeaturedImage1>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Banff-National-Park.jpg</FeaturedImage1>
      <FeaturedImage2>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Banff-National-Park.jpg</FeaturedImage2>
      <FeaturedImage3>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Banff-National-Park.jpg</FeaturedImage3>
   </attraction>
   <attraction>
      <ID>294</ID>
      <Title>Benaki Museum</Title>
      <FeaturedImage>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/kali.jpg</FeaturedImage>
      <FeaturedImage1>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Banff-National-Park.jpg</FeaturedImage1>
      <FeaturedImage2>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/09/Jellyfish.jpg</FeaturedImage2>
      <FeaturedImage3>http://tripatlas.s3.amazonaws.com/travel/wp-content/uploads/sites/10/2014/08/Banff-National-Park.jpg</FeaturedImage3>
   </attraction>
</Location>

上面是我的XML。我希望在xml解析后显示所有图像。当我打开Great Eastern Hotel时,它显示来自标签FeaturedImage,1,2和3的所有图像。类似于Benaki博物馆。

    static final String KEY_ITEM = "attraction"; // parent node
    static final String KEY_ID = "ID";
    static final String KEY_TITLE= "Title";

    static final String KEY_IMAGE = "FeaturedImage";
    static final String KEY_IMAGE1 = "FeaturedImage1";
    static final String KEY_IMAGE2 = "FeaturedImage2";
    static final String KEY_IMAGE3 = "FeaturedImage3";





    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    String xml = ParseXMLMethods8.getXML();
    Document doc = ParseXMLMethods8.XMLfromString(xml);
    int numResults = ParseXMLMethods8.numResults(doc);
    NodeList children = doc.getElementsByTagName(KEY_ITEM);

                   for (int i = 0; i < children.getLength(); i++) 
                   {                            
            HashMap<String, String> map = new HashMap<String, String>();    
            Element e = (Element)children.item(i);
            map.put("ID", ParseXMLMethods8.getValue(e, KEY_ID));
            map.put("Title", ParseXMLMethods8.getValue(e, KEY_TITLE));
            map.put("FeaturedImage", ParseXMLMethods8.getValue(e, KEY_IMAGE));
                            map.put("FeaturedImage1", ParseXMLMethods8.getValue(e, KEY_IMAGE1));
                            map.put("FeaturedImage2", ParseXMLMethods8.getValue(e, KEY_IMAGE2));
                            map.put("FeaturedImage3", ParseXMLMethods8.getValue(e, KEY_IMAGE3));

                            mylist.add(map);            
        }   

上面我编写了用于从XML解析中获取数据的代码。我的主要目的是每当点击一个标题时想要在gridView中显示此标题下的所有图像。只能在特定项目下看到一个图像而不是获取所有图像在gridView中。

0 个答案:

没有答案