【问题标题】:How to create a table with dynamic rows in Android如何在 Android 中创建具有动态行的表
【发布时间】:2011-06-30 03:35:26
【问题描述】:

我是 android 新手,我被以下难题困住了。

我需要在 Android 中创建一个如下所示的表:

类别 |商品名称 |获得的分数 |最大分数|


第 1 行信息


第 2 行信息


我面临的问题是这些行需要根据项目的数量动态创建。
我环顾四周,发现表格布局信息非常通用,或者没有显示如何创建动态表格。

附:由于积分不够,无法附上表格的确切图片

【问题讨论】:

    标签: android android-tablelayout


    【解决方案1】:

    你创造了这个。首先创建一个表。现在您知道了要(动态)创建的行数。

        private TableLayout myTableLay;
        private TableRow demoTableRow[];
        private String cat[],itemName[],marks[],maxMarks[];    
        private int count;
            public void example()
        {
          myTableLay = new TableLayout(this);
          myTableLay.removeAllViews();
          myTableLay.refreshDrawableState();
    
         // i hope now you got count.
          demoTableRow = new TableRow[count];
          cat = new String[count];
          itemName= new String[count];
          marks= new String[count];
          maxMarks= new String[count];
    
         for(int i=0;i<count;i++)
          {
             // add all inforamation to your tablerow in such a maaner that you want to display on screen.
    
    
         myTableLay.addView(demoTableRow[i);
           }
     //hope it might helpful.
        }
    

    【讨论】:

    • 但是用于为表格创建 ui 的 xml 文件呢?我如何包含这些信息?
    • 在 xml 文件中最后添加滚动视图并将表格添加到滚动视图中,以便它也可以滚动。
    • 所以我应该创建一个具有单个表格行的表格视图并使用此link中提供的示例代码
    猜你喜欢
    • 2013-07-28
    • 2021-06-26
    • 1970-01-01
    • 2021-03-14
    • 2018-12-02
    • 2023-04-05
    • 1970-01-01
    • 2011-06-28
    • 2021-02-17
    相关资源
    最近更新 更多