在android中的expandable listview中创建2组

时间:2012-08-14 04:16:07

标签: java android expandablelistview

您好我必须在我的可扩展listview android应用程序中创建2组..但是我无法开发这个。请帮助我。 这是我的代码:

SimpleExpandableListAdapter expListAdapter =
        new SimpleExpandableListAdapter(
                this,
                createGroupList(),              // Creating group List.
                R.layout.group_row,             // Group item layout XML.
                new String[] { "OrderInfo","CustomerInfo"},  // the key of group item.
                new int[] { R.id.order,R.id.customer},

                // ID of each group item.-Data under the key goes into this TextView.
                createChildList(),              // childData describes second-level entries.
                R.layout.single_list_item,  
              //  new String[] {"KEY_ARTIST"},  
               // new int[] { R.id.payment_label}  // Keys in childData maps to display.
                  // Layout for sub-level entries(second level).
               new String[] {"KEY_ARTIST","KEY_DURATION","KEY_SUBTOTAL","KEY_DISCOUNT","KEY_COUPON","KEY_COST"},  
               new int[] { R.id.payment_label,R.id.total_label,R.id.discount_label,R.id.discount_label,R.id.coupon_label,R.id.cost_label}// Keys in childData maps to display.
             //   new int[] { R.id.payment_label,R.id.total_label}     // Data under the keys above go into these TextViews.
            );
        setListAdapter( expListAdapter );       // setting the adapter in the list.

    }catch(Exception e){
        System.out.println("Errrr +++ " + e.getMessage());
    }
}

/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
      ArrayList result = new ArrayList();
      for( int i = 0 ; i < 2 ; ++i ) { // 15 groups........
        HashMap m = new HashMap();
       m.put( "OrderInfo","CustomerInfo " + i ); // the key and it's value.


        result.add( m );
      }
      return (List)result;

}

这里我要创建2组orderinfo和customerinfo..how是创建上面的代码..请帮助我。

1 个答案:

答案 0 :(得分:0)

我认为这是创建Expandable List View的正确方法。但可能存在问题。所以请仔细阅读link

请检查您是否必须按ExpandableListActivity

扩展您的活动

布局中的

android:id="@+id/android:list"

提供ExpandableListView的ID