2012-01-10 2 views
1

Activity.OnContentChanged에서 모든 컨트롤을 반복하여 태그를 표시하고 싶습니다.MonoDroid : 액티비티의 컨트롤을 반복 하시겠습니까?

나는 그것이 base.Window.HasChildren과 관련이 있다고 가정하지만 실제로 아이들을 얻는 방법을 알 수는 없습니다.

EDIT : 대부분의 레이아웃의 기본 클래스 인 ViewGroup에는 GetChildCount 및 GetChildAt가 있습니다. 하지만 여전히 액티비티에서 루트 수준 레이아웃으로 이동하는 방법을 알 수 없습니다.

답변

0
var viewGroup = this.Window.DecorView as ViewGroup; 
if(viewGroup != null){ 
for (int i = 0; i < view.ChildCount; i++) 
{ 
    var control = view.GetChildAt(i); 
} 
} 
3

당신은 당신의 레이아웃의 루트 요소에 ID를 할당하고 그 통해 액세스 할 수 있습니다

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Root" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="1"/> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="2"/> 
</LinearLayout> 

그런 다음 활동에 당신이 할 수있는 일 같은 :

var root = FindViewById<LinearLayout>(Resource.Id.Root); 

for (int i = 0; i < root.ChildCount; i++) 
{ 
    Console.WriteLine(root.GetChildAt(i).Id); 
}