-1
我試圖從視圖中返回一個按鈕對象,隨後運行setText
。 雖然我很難轉換它。 任何意見讚賞。從視圖中獲取按鈕
public Button aiPlayerPick() {
Button btn = null;
TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout);
for (int rowIndex = 0; rowIndex < tableLayout.getChildCount(); rowIndex++) {
View tableLayoutChild = tableLayout.getChildAt(rowIndex);
if (tableLayoutChild instanceof TableRow) {
for (int i = 0; i < ((ViewGroup) tableLayoutChild).getChildCount(); i++) {
View view = ((ViewGroup) tableLayoutChild).getChildAt(i);
if (view instanceof Button && view.getTag() == aiPickedButton) {
View btn_v = view.findViewWithTag(aiPickedButton);
System.out.println("Button: " + btn_v);
btn = (Button) findViewById(R.id.btn_v); // Problem is here, I can't get that view to be seen as a button
break;
} else {
i++;
}
}
}
}
return btn;
}
試過,但它仍然有或多或少相同的問題。 'btn_v'不被識別 –
btn =(Button)view.findViewWithTag(aiPickedButton);只是使用你已經擁有它 – Xjasz