Android 我在列表视图中有一个表布局

Android 我在列表视图中有一个表布局,android,Android,我在列表视图中有一个表视图 我想让桌子充满活力。有固定的3列,但行数不同 每个单元格中都有一个图像。我希望有尽可能多的表单元格的图像数量。列表视图的每一行中的表行数各不相同 当我创建表格时,图像被添加到最后一个单元格中 public class BrandView extends LinearLayout { TableLayout table_layout; Context context; Brand brand; CheckBox chkType,c

我在列表视图中有一个表视图

我想让桌子充满活力。有固定的3列,但行数不同

每个单元格中都有一个图像。我希望有尽可能多的表单元格的图像数量。列表视图的每一行中的表行数各不相同

当我创建表格时,图像被添加到最后一个单元格中

public class BrandView extends LinearLayout {

    TableLayout table_layout;
     Context context;
     Brand brand;
     CheckBox chkType,chkName;
     TextView txtTypeName,txtBrandName;
     ImageView imgBrandImage;

    public BrandView(Context context) {
        super(context);
        this.context=context;
        HookUp();
    }

    public void setBrandView( Brand brand){
        this.brand=brand;

        imgBrandImage.setImageResource(brand.getImage());
        txtTypeName.setText(brand.getTypeName());
    }

    public  void HookUp(){
        LayoutInflater inflater=LayoutInflater.from(context);
        View view=inflater.inflate(R.layout.lay_brand_select_view,null);
        chkType=(CheckBox) view.findViewById(R.id.chkType);
        txtTypeName=(TextView) view.findViewById(R.id.txtTypeName);
        table_layout=(TableLayout) view.findViewById(R.id.tableLayout1);

        BuildTable(1,1);
        this.addView(view);
    }


     private void BuildTable(int rows, int cols) {


        // outer for loop
        for (int i = 1; i <= rows; i++) {

            TableRow row = new TableRow(context);
            row.setLayoutParams(new TableRow.LayoutParams(200,
                    200));

            // inner for loop
            for (int j = 1; j <= cols; j++) {

                LayoutInflater inflater = LayoutInflater.from(context);
                View tv = inflater.inflate(R.layout.lay_table, null);
                chkName=(CheckBox) tv.findViewById(R.id.chkName);
                txtBrandName=(TextView) tv.findViewById(R.id.txtBrandName);
                imgBrandImage=(ImageView) tv.findViewById(R.id.imgBrandImage);
                row.addView(tv);

                }

                table_layout.addView(row, new TableLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT,
                        LayoutParams.WRAP_CONTENT));

              /*  if(i==rows)
                    for(int l=k;l>0;l--)
                        row.removeViewAt(l);*/

        }
   }
}
公共类BrandView扩展了LinearLayout{
表布局表_布局;
语境;
品牌;
复选框chkType,chkName;
TextView txtTypeName、txtBrandName;
ImageView imgBrandImage;
公共品牌视图(上下文){
超级(上下文);
this.context=context;
连接();
}
公共景观(品牌){
这个。品牌=品牌;
imgBrandImage.setImageResource(brand.getImage());
txtypename.setText(brand.getTypeName());
}
公共连接(){
LayoutFlater充气机=LayoutFlater.from(上下文);
视图=充气机。充气(右布局。布局\u品牌\u选择\u视图,空);
chkType=(复选框)view.findViewById(R.id.chkType);
txtTypeName=(TextView)view.findViewById(R.id.txtTypeName);
table_layout=(TableLayout)view.findviewbyd(R.id.tableLayout1);
构建表(1,1);
这个.addView(视图);
}
私有void构建表(int行、int列){
//外循环

对于(int i=1;i您应该像在
BuildTable()
方法中那样,通过编程将行添加到
TableView
中。重点是每次在
ListView
的适配器
getView()
方法中都需要调用此方法。

我尝试调用BuildTable()方法,但它仍然不起作用。演示您是如何做到的。另外,您最好将此方法从视图类中移出,并通过相应的修改将其移到适配器类中。并从
getView()
调用,将表视图传递给。我们可以创建单个表单元格而不是行吗?表单元格需要表行(它就像一个单元格),因此您需要先添加一行,然后再向该行添加任何其他小部件。然后对下一个单元格重复此操作。您能否给出一些代码,说明如何将表格单元格动态添加到该行