我正在向具有特定值的哈希图添加一个数组。我无法从 listview 单击项目中检索具有特定值的 arraylist 值。
HashMap<String, ArrayList<SeatList>> example = new HashMap<String, ArrayList<SeatList>>();
ArrayList<SeatList> seatlistarray;
ArrayList<Item> items = new ArrayList<Item>();
Item 和 SeatList 是 bean 类。
///////////////////////////
for (int i = 0; i < nodeList.getLength(); i++)
{
Element e = (Element) nodeList.item(i);
Node seat=(Node)seatlist.item(k);
if(seat.hasChildNodes()){
NodeList seats=seat.getChildNodes();
for(int m=0;m<seats.getLength();m++){
Node seatf=(Node)seats.item(m);
if (seatf.getNodeType() == Node.ELEMENT_NODE) {
HashMap hash=new HashMap();
Element eElement = (Element) seatf;
seatlistarray=new ArrayList<SeatList>();
hash.put("ID", eElement.getElementsByTagName("ID").item(0).getTextContent());
hash.put("X_pos", eElement.getElementsByTagName("X_pos").item(0).getTextContent());
hash.put("Y_pos", eElement.getElementsByTagName("Y_pos").item(0).getTextContent());
hash.put("Radius", eElement.getElementsByTagName("Radius").item(0).getTextContent());
seatlistarray.add(new SeatList(eElement.getElementsByTagName("ID").item(0).getTextContent()));
}}}}
example.put(parser.getValue(e, "Hall-ID"), seatlistarray);
items.add(new EntryItem(parser.getValue(e, NODE_NAME), parser.getValue(e, NODE_DESIGNATION),parser.getValue(e, "Hall-ID")));
}
这里listview点击监听功能:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
if(!items.get(position).isSection()){
EntryItem item = (EntryItem)items.get(position);
Toast.makeText(this, "You clicked " + item.VenueName , Toast.LENGTH_SHORT).show();
ListIterator<SeatList> testExtracted = example.get(item.HallID).listIterator();
if(testExtracted.hasNext()){
System.out.println("MYUID:"+testExtracted.next().getID());
}
super.onListItemClick(l, v, position, id);
}
}