1 つのアクティビティですべてのトグルボタンをループして、2 つのいずれかを実行しようとしています。値を設定したい場合もあれば、値を読み取りたい場合もあります。これを行う最も簡単な方法は、子をループし、トグルボタンのタイプを確認してから、前述のタスクを実行することですか?
このようなものを使用しますか?
for (int i = 0; i < rootView.getChildCount(); i++)
if (Widget_Tag != null){
View Current_Widget = (View) rootView.getChildAt(i);
String Widget_Tag = (String) Current_Widget.getTag();
if (Widget_Tag.equals("MyToggleButton")) {
//do something
}
}
** * ***更新* ** * **
次のような作業コード (回答ありがとうございます)、別の for ループをネストして、ToggleButtons の 1 つの子レイヤーを掘り下げました。
ViewGroup rootView = (ViewGroup) findViewById(R.id.LayoutHere);
for (int i = 0; i < rootView.getChildCount(); i++) {
ViewGroup nextLayout = (ViewGroup) rootView.getChildAt(i);
for (int i2 = 0; i2 < nextLayout.getChildCount(); i2++) {
View Current_Widget = nextLayout.getChildAt(i2);
if(Current_Widget instanceof ToggleButton)
{
//Do Something
}
}
}