如何显示包含父和子动态更新的可扩展ListView?

时间:2012-04-27 10:21:02

标签: android listview expandablelistview expandablelistadapter

我想显示包含父级和子级甚至子子级的可扩展列表视图。 这些数据将从服务器访问。数据可以作为JSON数据返回。

我想访问与该父级关联的父级和子级。孩子也可能有子女。

 Ex:
  Name       Parent        Level       categoryId
  Audio       0               1           101
  Video       0               1           102
  songs      101              2           201
  data       101              2           202
  myhost     201              3           301
  HD         102              2           401
  TV         401              3           500

以上示例显示了现在可用的数据。

我的代码已附上

try {
    res1= httpclient1.execute(httppost1);
    responseBodys1 =EntityUtils.toString(res1.getEntity());

    JSONObject jsObject = new JSONObject(responseBodys1);
    JSONArray demo= jsObject.getJSONArray("categories");

    System.out.println("demo=="+demo.length());
    ArrayList<String> map = new ArrayList<String>();
    childs.add(new ArrayList<ArrayList<String>>());
    ArrayList<Integer> map1 = new ArrayList<Integer>();
    ArrayList<Integer> map3 = new ArrayList<Integer>();

    for(int i=0;i<demo.length();i++)

    {
        JSONObject movie = demo.getJSONObject(i);
           ctName = movie.getString("ctName");
           ctParent= movie.getInt("ctParent");
           int ctLevel = movie.getInt("ctLevel");
           ctCategoryId=movie.getInt("ctCategoryId");
           map.add(ctName);
          map1.add(ctParent);
          // map1.add(ctLevel);
           map3.add(ctCategoryId);

          System.out.println("Map1-===>"+map);
           System.out.println("Map3-===>"+map3);

          if(ctParent==0)
          {
           groups.add(ctName);
          }

           if(ctParent!=0)
           {
             int ctP= movie.getInt("ctParent");
             System.out.println("ctp-->"+ctP);
             for(int j=0;j<demo.length();j++)
             {


             if(ctP==ctCategoryId)
             {
                 System.out.println("matched--"+ctP+"=="+ctCategoryId);
                childs.add(new ArrayList<ArrayList<String>>());
                childs.get(i).add(new ArrayList<String>());
                 childs.get(i).get(j).add(ctName);

             }

           }
           }

我想把孩子放到相应的父母那里。在上面的代码中,它只返回父母。孩子们不会被展示,也不会出现在各自的父母身边。

我想比较类别ID和父类,并将所有数据相互放在一起。最后它返回到可扩展列表类。

所以任何人都会帮助我。如何执行此操作。 ???????????

0 个答案:

没有答案