如何在一个活动中创建两个不同的android耗材列表?

如何在一个活动中创建两个不同的android耗材列表?,android,expandablelistview,Android,Expandablelistview,我正在开发我的android应用程序。我需要一个创建一个有两个可扩展列表的活动。这些列表将有不同的布局。因此,这些列表将完全不同。如何将两个列表添加到主布局?如何将“setadapter”用于这些不同的列表?请给我一些建议,如果可能的话,一些示例代码 多谢各位 编辑: 感谢您的回复,但我应该在哪里调用开关函数(setListAdapter(expListAdapter2)?我在onGroupExpand中尝试了它,但它无法正常工作。当我单击“任意组”时,我需要更新特定组而不是整个列表,如果您有想

我正在开发我的android应用程序。我需要一个创建一个有两个可扩展列表的活动。这些列表将有不同的布局。因此,这些列表将完全不同。如何将两个列表添加到主布局?如何将“setadapter”用于这些不同的列表?请给我一些建议,如果可能的话,一些示例代码

多谢各位

编辑:


感谢您的回复,但我应该在哪里调用开关函数(setListAdapter(expListAdapter2)?我在onGroupExpand中尝试了它,但它无法正常工作。当我单击“任意组”时,我需要更新特定组而不是整个列表,如果您有想法,请帮助我?

您可以通过在onCreate方法中创建另一个适配器来完成此操作

采取以下措施

public void onCreate(Bundle savedInstanceState) {
        try{
             super.onCreate(savedInstanceState);
             setContentView(R.layout.main);
             button1 = (Button) findViewById(R.id.button1);

        final SimpleExpandableListAdapter expListAdapter =
            new SimpleExpandableListAdapter(
                        //FOR LEVEL 1 SCREEN
                    this,
                    createGroupList(),              // METHOD TO CREATE PARENTLIST Creating group List.
                    R.layout.group_row,             // REF TO XML FILENAME.         
                    new String[] { "Group Item" },  // STRING ARRAY HOLDING ONE KEY THAT REF'S ALL PARENT LIST ITEMS.
                    new int[] { R.id.row_name },    // REF TO I.D. OF PARENT XML. ID of each group item.-Data under the key goes into this TextView.                    
                    createChildList(),              // METHOD TO CREATE CHILD LST. childData describes second-level entries.
                    R.layout.child_row,             // XMLFILE NAME FOR CHILD LIST.Layout for sub-level entries(second level).
                    new String[] {"Sub Item"},      // KEY FOR CHILD ITEMS IN HASHMAP. Keys in childData maps to display.
                    new int[] { R.id.grp_child}     // XML ID FOR TEXTVIEW. Data under the keys above go into these TextViews.
                );

            setListAdapter( expListAdapter );// THIS IS WHAT YOU NEED TO CHANGE.
因此,如果您现在(在onCreate方法中)复制expListAdapter并创建另一个名为expListAdapter2的数组,(您将需要使用列表项创建新数组,并复制和重命名“createGroupList()”方法。然后,只需将“设置适配器”行更改为:

setListAdapter(expListAdapter2); 
以下是我使用的creategroup和createchild方法:

@SuppressWarnings("unchecked")
    private List createGroupList() { 
          ArrayList result = new ArrayList();
        for( int i = 0 ; i < arrGroupelements.length; ++i ) { // for all elements in array........
            HashMap m = new HashMap();
            m.put("Group Item", arrGroupelements[i]); // the key and it's value.
            result.add( m );

            }     //in the end we have an array list


          return (List)result;
    }    


    @SuppressWarnings("unchecked")
    private List createChildList() {

        ArrayList result = new ArrayList();
        for( int i = 0 ; i < arrGroupelements.length ; ++i ) { // for each parent item
          ArrayList secList = new ArrayList(); 
          for( int n = 0 ; n < arrChildelements[i].length ; n++ ) {
            HashMap child = new HashMap();
            child.put("Sub Item", arrChildelements[i][n]);          
            secList.add( child );
          }
         result.add( secList );


        }        
        return result;
    }
@SuppressWarnings(“未选中”)
私有列表createGroupList(){
ArrayList结果=新建ArrayList();
对于(int i=0;i

希望有助于在单个布局中扩展两个列表

expandableListAdapter = new SimpleExpandableListAdapter(getApplicationContext(), createGroupList(),R.layout.reportsales_date, new String[] {"billdatevoid", "amount" }, new int[] {R.id.sales_date, R.id.sales_total },createChildList(), R.layout.reportsales_date1,
new String[] { "bill_num", "orderid" }, new int[] {R.id.bill_num, R.id.price });
setListAdapter(expandableListAdapter);

expandableListView = (ExpandableListView) findViewById(R.id.expandableListView1);
expListAdapter = new SimpleExpandableListAdapter(getApplicationContext(), createGroupList1(),R.layout.report_date, new String[] { "GroupItem","GroupItem1" }, new int[] { R.id.datedate,R.id.datedate1 },createChildList1(), R.layout.report_date1,
new String[] { "InvoiceNo", "Invoiceamt" },new int[] { R.id.datebillno, R.id.dateamt });
expandableListView.setAdapter(expListAdapter);

看看这是否有帮助,谢谢,我现在正在查找您在哪里调用“setListAdapter(expListAdapter2)”?我应该在哪里调用开关函数?我在“OnChildClickExpensable”中尝试过,但不起作用,您在哪里做的?