2015-11-19 21 views
0

我在我的应用程序中有可扩展列表视图。数据存储在这样:getChild()方法使得错误

ArrayList<Map<String, String>> groupData; 
    ArrayList<Map<String, String>> childDataItem; 
    ArrayList<ArrayList<Map<String, String>>> childData;  
    Map<String, String> m; 

当我使用方法getChild()

@Override 
    public Object getChild(int groupPosition, int childPosititon) { 
     return this.childData.get(groupData.get(groupPosition)).get(childPosititon); 
    } 

这使得groupData.get(groupPosition))

错误怎么解决呢?

+0

你能在这里粘贴你的错误吗? – Nikki

+0

请添加您收到的堆栈跟踪。 – Messer

+0

错误:(666,24)错误:发现没有得到合适的方法(图<字符串,字符串>) 方法ArrayList.get(INT)是不适用 (实际参数地图<字符串,字符串>不能被转换为int通过方法调用转换) 方法AbstractList.get(INT)是不适用 (实际参数地图<字符串,字符串>不能转换通过方法调用转换为int) – userpixel

回答

2

你误解的东西 - ArrayList的工作整数位置键

所以 - >groupData.get(groupPosition)返回字符串 那么你不能做childData.get(groupData.get(groupPosition))

你也应该考虑像=>

列表
HashMap<String,<Map<String, String>> values; 

在这里你有父/子只有一个列表。

+0

对不起我是beginner..and什么我应该现在做吗? – userpixel

0
HashMap<String,<Map<String, String>> values; 

与:

@Override 
public Object getChild(int groupPosition, int childPosititon) { 
    String key = values.keyset().get(groupPosition); //Father key look how words hashmap on oracle site; 
    parentElement = values.get(key); 
    childKey = parentElement.keyset().get(childPosititon); 
    return parentElement.get(childKey) 
} 

我没有因式分解代码来让你了解它是如何工作的。按照我所说的看看workds list/Map/Set。这非常重要,并会帮助你做一个更干净的代码。

+0

以及我应该如何填写HashMap? – userpixel