在TableLayout中,有3个3×3格式的按钮.如何使用TableLayout(不是按钮ID)的id以编程方式访问这些按钮上的文本?
解决方法
使用类似的东西,
TableLayout tblLayout = (TableLayout)findViewById(R.id.tableLayout); TableRow row = (TableRow)tblLayout.getChildAt(0); // Here get row id depending on number of row Button button = (Button)row.getChildAt(XXX); // get child index on particular row String buttonText = button.getText().toString();
3×3格式:(理解实际的代码可能不同)
for(int i=0;i<3;i++)
{
TableRow row = (TableRow)tblLayout.getChildAt(i);
for(int j=0;j<3;j++){
Button button = (Button)row.getChildAt(j); // get child index on particular row
String buttonText = button.getText().toString();
Log.i("Button index: "+(i+j),buttonText);
}
}