我想实现TableLayout
分页,在第 1 页显示 10 条记录,然后在第 2 页显示下 10 条记录,依此类推……我正在使用表格布局,但没有得到所需的结果。使用本教程,表格只是水平而不是垂直增长。如何更改它以使其也垂直增长,然后当记录大小大于 10 时转移到下一页?
编码:
public class Sample extends Activity {
String companies[] = {"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung","Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung"};
String os[] = {"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada","Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada"};
TextView companyTV,valueTV,deviceTv,actionTv,dateTv,timeTv,creditTv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// creates the Pagination Layout
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));
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row);
TableRow row2 = new TableRow(this);
row2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row2);
for (int i=0;i<companies.length;i++)
{
deviceTv = new TextView(this);
deviceTv.setText(companies[i]);
deviceTv.setTextColor(Color.RED);
deviceTv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
deviceTv.setPadding(5, 5, 5, 5);
row2.addView(deviceTv);
actionTv = new TextView(this);
actionTv.setText(os[i]);
actionTv.setTextColor(Color.GREEN);
actionTv.setPadding(5, 5, 5, 5);
actionTv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
row2.addView(actionTv); // Adding textView to tablerow.
}
/* 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);
}