Q&A
LinearLayoutの中に入っているTextViewだけを取得したいです。
getChildAt()を使って無理やり取得することは出来そうですが階層が変わった時にコードを変更する必要があったりと複雑になってしまうかと思っております。
レイアウトは下記の様な形でidがparentに設定してあるLinearLayout内のTextViewを全て(直下だけではなく孫?の階層までの全て)を取得したいです。
<LinearLayout android:id="@+id/parent" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> </LinearLayout>
何か良い方法はありますでしょうか?よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。