2011-03-25 53 views
0

我已經從XML文件中解析出數據並將其存儲在arraylist.and中,我想將arraylist的內容複製到hashmap.i m中提供dis代碼。從arraylist中提取值並將其提供給hashmap

ArrayList<String> items=new ArrayList<String>(); 
     ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 
     HashMap<String, String> map = new HashMap<String, String>(); 

     try { 
      XmlPullParser xpp=getResources().getXml(R.xml.call_record_request_structure); 
      while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) { 
      if (xpp.getEventType()==XmlPullParser.START_TAG) { 
       String name=xpp.getName(); 
       String temp="productName"; 
       //items.add(name); 
      if (name.equals(temp)) { 
      String pro=xpp.nextText(); 
       items.add(pro); 
       int count=items.size(); 
       for(int i=0;i<count;i++) { 
        map = new HashMap<String, String>(); 
        map.put("product", items.get(i)); 
        mylist.add(map); 
       } 
      } 
      } 
      xpp.next(); 
      } 
      } 
      catch (Throwable t) { 
      Toast 
      .makeText(this, "Request failed: "+t.toString(), 4000) 
      .show(); 
      } 
SimpleAdapter mHistory = new SimpleAdapter(this,mylist , R.layout.prodlist_supp, 
        new String[] {"product"}, 
        new int[] {R.id.products}); 
     listview.setAdapter(mHistory); 

但是當我運行的代碼IT方面crashing.can誰能幫我

+0

它在哪裏崩潰?顯示你的堆棧跟蹤! – Olegas 2011-03-25 12:57:22

+0

發佈您的堆棧trace..we無法做任何事情沒有 – Udaykiran 2011-03-25 13:03:38

回答

0

試試這個:循環結束之後添加地圖。

map = new HashMap<String, String>(); 

for(int i=0;i<count;i++) { 

      map.put("product", items.get(i)); 

     } 
mylist.add(map); 

如果問題仍然存在顯示您的堆棧跟蹤。

相關問題