Ho un numero di righe nel mio TableLayout e voglio accedere alle visualizzazioni dei pulsanti. Esempio come segue:
<TableLayout>
<TableRow>
<Button />
<Button />
</TableRow>
<TableRow>
<Button />
<Button />
</TableRow>
</TableLayout>
Dal layout della tabella vorrei scorrere tra i pulsanti.
TableLayout layout=(TableLayout) findViewById(R.id.Layout);
layout.getChildCount;
Quanto sopra restituisce solo le visualizzazioni della tabella numerica.
risposte:
3 per risposta № 1Prova così, potrebbe esserti d'aiuto
TableLayout layout = (TableLayout) findViewById(R.id.Table_ID);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof TableRow) {
TableRow row = (TableRow) child;
for (int x = 0; x < row.getChildCount(); x++) {
View view = row.getChildAt(x);//Here you get Your Button View
}
}
}
0 per risposta № 2
Prova questo:
TableLayout layout=(TableLayout) findViewById(R.id.Layout);
for(int i=0;i<layout.getChildCount();i++) {
if (layout.getChildAt(i) instanceof TableRow) {
TableRow tableRow = (TableRow) layout.getChildAt(i);
for(int j=0;j<tableRow.getChildCount();j++) {
if (tableRow.getChildAt(j) instanceof Button) {
Button button = (Button) tableRow.getChildAt(j);
//your button is here
}
}
}
}