【问题标题】:How to add a table layout to ExpandableListView as a child item.如何将表格布局作为子项添加到 ExpandableListView。
【发布时间】:2012-02-12 06:10:31
【问题描述】:

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

谢谢

【问题讨论】:

标签: android adapter expandablelistview


【解决方案1】:

BaseExpandableListView 中的子视图

    @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;
}

【讨论】:

    猜你喜欢
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多