這可能有助於
public class Test extends Activity{
List<Button> buttonList;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonList=new ArrayList<Button>();
Button doneButton=(Button)findViewById(R.id.your_final_button);
ScrollView view=(ScrollView)findViewById(R.id.your_scroll_view);
view.addView(tableLayout(20));//20 rows
doneButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for(Button b : buttonList){
b.getText();//whatever you wanna do
}
}
});
}
private TableLayout tableLayout(int count) {
TableLayout tableLayout = new TableLayout(this);
tableLayout.setStretchAllColumns(true);
tableLayout.setBackgroundColor(Color.WHITE);
int noOfRows = count ;
for (int i = 0; i < (noOfRows+1); i++) {
int rowId = 3 * i;
tableLayout.addView(createOneFullRow(rowId));
}
return tableLayout;
}
private TableRow createOneFullRow(int rowId) {
TableRow tableRow = new TableRow(this);
tableRow.setPadding(0, 10, 0, 0);
//6 columns
tableRow.addView(createButton("text1"));
tableRow.addView(createButton("text2"));
tableRow.addView(createButton("text3"));
tableRow.addView(createButton("text4"));
tableRow.addView(createButton("text5"));
tableRow.addView(createButton("text6"));
return tableRow;
}
private View createButton(String string) {
// TODO Auto-generated method stub
Button button = new Button(this);
button.setText(string);
buttonList.add(button);
return button;
}
}
謝謝你這麼多努力爲您回答這個問題。我期待着嘗試代碼。我很抱歉,我不能投票,我還沒有15分。 – cd141186 2015-02-07 22:37:28
我認爲你可以接受答案而不是投票。 – 2015-02-09 05:58:23
太棒了。我會看看如果我可以得到它的工作。 – cd141186 2015-02-09 13:46:21