我有arrayList {1,2,3,4,5,6,7,8,9},我只想每次显示4个按钮1,2,3,4,如果用户点击下一步就会删除前4个按钮并显示5,6,7,8。
示例:
1 2
3 4
4 6
7 8
当用户点击下一个按钮时
9
这是2x2显示方法
private void dynamicBtnDisplay() {
try{
for(int index = 0; index < 4; index++){
TableLayout table = (TableLayout) findViewById( R.id.buttonLayout );
int buttonsInRow = 0;
int numRows = table.getChildCount();
TableRow row = null;
if( numRows > 0 ){
row = (TableRow) table.getChildAt( numRows - 1 );
buttonsInRow = row.getChildCount();
}
if( numRows == 0 || buttonsInRow == 2 ){
row = new TableRow( this );
table.addView( row );
buttonsInRow = 0;
}
if( buttonsInRow < 2 ){
ToggleButton bb = new ToggleButton( this );
row.addView( bb, 300, 200 );
bb.setText(myArr[index]);
}
}
}catch (NullPointerException e){
}
}