/ / बाल तत्वों के बच्चे - जावा, एंड्रॉइड, एक्सएमएल

बाल तत्वों का बच्चा - जावा, एंड्रॉइड, एक्सएमएल

मेरे TableLayout में कई पंक्तियाँ हैं और मैं बटन दृश्यों तक पहुँच चाहता हूँ। उदाहरण इस प्रकार है:

<TableLayout>
<TableRow>
<Button />
<Button />
</TableRow>
<TableRow>
<Button />
<Button />
</TableRow>
</TableLayout>

टेबल लेआउट से मैं बटन के माध्यम से लूप करना चाहूंगा।

TableLayout layout=(TableLayout) findViewById(R.id.Layout);
layout.getChildCount;

उपरोक्त केवल संख्या सारणीमान दृश्य देता है

उत्तर:

जवाब के लिए 3 № 1

इस तरह की कोशिश करें, यह आपकी मदद कर सकता है

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 № 2

इसे इस्तेमाल करे:

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
}
}
}
}