如何将表格布局添加到ExpandableListView作为子项目。

时间:2012-01-17 12:31:06

标签: android adapter expandablelistview

  

我想将一个表格布局添加到ExpandableListView作为子项目。所以当我们点击组数据时,它的适配器会显示一个表格布局。

由于

1 个答案:

答案 0 :(得分:0)

Base ExpandableListView中的子视图

    @Override
public View getChildView( int groupPosition,  int childPosition,
         boolean isLastChild,  View convertView,  ViewGroup parent) {
    TableLayout layout = new TableLayout(this.context);
    layout.setStretchAllColumns(true);
    TableRow tr1 = null;
    if(groupPosition==0){
        Toast.makeText(context, "text in if"+convertView, Toast.LENGTH_SHORT).show();
                if(childPosition==0){             
                     tr1 =new TableRow(this.context);
                     TextView tv = new TextView(this.context);
                    tv.setText("one");
                    tv.setTextColor(Color.YELLOW);                              
                    tr1.addView(tv);
                    layout.addView(tr1);
                }
                if(childPosition==1){
                     tr1 =new TableRow(this.context);
                     TextView tv = new TextView(this.context);
                    tv.setText("two");
                    tv.setTextColor(Color.YELLOW);                                
                    tr1.addView(tv);
                    layout.addView(tr1);
                }
                if (isLastChild) {
                    if(pos_child==0){
                        layout=getObj();
                        }
                        else if(pos_child==1){
                            TableRow tr3 =new TableRow(this.context);
                            TextView tv = new TextView(this.context);
                            tv.setText("ameta");
                            tr3.addView(tv);
                            layout.addView(tr3);
                        }
                }
    }
    return layout;
}