动态子项添加到android可扩展列表视图中

时间:2012-08-18 04:42:30

标签: java android xml-parsing expandablelistview expandablelistadapter

我必须使用下面的代码...我必须获得第一组的子值...但在这里我必须单击第二组意味着它不会扩展,同时应用程序强制关闭。所以请帮助我。 .how为不同的父母赋予不同的孩子价值....请给我示例代码...

private List createGroupList() {

    Log.d(TAG, "Adding groups values");
    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> statusMap = new HashMap<String, String>();
    statusMap.put(GroupID, "OrderInfo");
    list.add(statusMap);
    HashMap<String, String> usersMap = new HashMap<String, String>();
    usersMap.put(GroupID, "CustomerInfo");
    list.add(usersMap);
    Log.d(TAG, "Adding groups values successfull");
    return list;
}


 private List createChildList() {

    ArrayList result = new ArrayList();
    for( int i = 0 ; i < 1 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
      /* each group need each HashMap-Here for each group we have 3 subgroups */
      ArrayList secList = new ArrayList();
      for( int n = 0 ; n < 1 ; n++ ) {
        HashMap child = new HashMap();


       String s= getIntent().getStringExtra("payment_method");
       String s1= getIntent().getStringExtra("total");
       String s2= getIntent().getStringExtra("firstname");
       String s3= getIntent().getStringExtra("lastname");

     child.put( "KEY_ARTIST", s);
     child.put( "KEY_DURATION", s1);
     child.put( "KEY_FNAME", s2);
     child.put( "KEY_LNAME", s3);

        secList.add( child);
      }
     result.add( secList );
    }
    return result;
}

1 个答案:

答案 0 :(得分:0)

使用此代码:

final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

    final HashMap<String, String> group1 = new HashMap<String, String>();
    group1.put(NAME, "OrderInfo");
    headerData.add( group1 );

    final HashMap<String, String> group2 = new HashMap<String, String>();
    group2.put(NAME, "CustomerInfo");
    headerData.add( group2);

    final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

    final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
    childData.add(group1data);

    final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
    childData.add(group2data);

上面的代码对我有用....所以请尝试使用上面的代码。