如何在android中的动态表视图中创建分页

时间:2015-04-01 12:21:41

标签: android

PaginationLayout paginationLayout = new PaginationLayout(this);
        paginationLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    // creates content only for sample
    TableLayout table = new TableLayout(this);
    table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    table.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);

    TableRow row = new TableRow(this);
    row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    table.addView(row);

    TableRow row2 = new TableRow(this);
    row2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    table.addView(row2);

    for(int i = 0; i< 50;i++){
        Button button = new Button(this);
        button.setText("Button " + i);
        if (i%2==0) {
            row.addView(button);
        } else {
            row2.addView(button);
        }
    }

    // add the content in pagination
    paginationLayout.addView(table);
    // set pagination layout
    setContentView(paginationLayout);
}

1 个答案:

答案 0 :(得分:0)

首先,Pagination最好使用ListView而不是TableLayout。使用ListView,您的数据和UI将由适配器轻松管理。

参见此示例

https://github.com/nicolasjafelle/PagingListView