2012-01-10 11 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); 
} 
関連する問題