如何使用java代码在android中创建多列表视图?

如何使用java代码在android中创建多列表视图?,android,tableview,Android,Tableview,我正在开发一个android应用程序。为此,我需要一个动态的tableView。我正在使用android中可用的TableLayout。但是我找不到在tableView中包含多个列的方法。有什么选择吗?我不知道我是否完全理解你的问题,但这里: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TableLayout tableLayout

我正在开发一个android应用程序。为此,我需要一个动态的tableView。我正在使用android中可用的TableLayout。但是我找不到在tableView中包含多个列的方法。有什么选择吗?

我不知道我是否完全理解你的问题,但这里:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    TableLayout tableLayout = new TableLayout(getApplicationContext());
    TableRow tableRow;
    TextView textView;

    for (int i = 0; i < 4; i++) {
        tableRow = new TableRow(getApplicationContext());
        for (int j = 0; j < 3; j++) {
            textView = new TextView(getApplicationContext());
            textView.setText("test");
            textView.setPadding(20, 20, 20, 20);
            tableRow.addView(textView);
        }
        tableLayout.addView(tableRow);
    }
    setContentView(tableLayout);
}
@覆盖
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TableLayout TableLayout=新的TableLayout(getApplicationContext());
TableRow TableRow;
文本视图文本视图;
对于(int i=0;i<4;i++){
tableRow=新的tableRow(getApplicationContext());
对于(int j=0;j<3;j++){
textView=新的textView(getApplicationContext());
setText(“测试”);
设置填充(20,20,20,20);
tableRow.addView(textView);
}
tableLayout.addView(tableRow);
}
setContentView(tableLayout);
}

这段代码创建了3列4行的TableLayout。基本上,您可以在XML文件中声明TableLayout,然后将ContentView设置为XML,并使用findViewById查找TableLayout。只有TableRow及其子项必须在java代码中完成。

您可以在设计视图中添加任意数量的列。您所要做的就是将任何要显示为列的视图元素放入Tabalow标记中

<TableLayout>
  <TableRow>
    <TextView></TextView> // That's a column
    <ImageView></ImageView>  // That's other column
    ....

    <Other views></Other views> // That's the last column
  </TableRow>
 </TableLayout>

//那是一个专栏
//那是另一个专栏
....
//这是最后一栏

< /代码>没有问题,如果这就是你所需要的,你应该考虑把这个问题标记为“回答”。