C# 适用于Android的平板Mono

C# 适用于Android的平板Mono,c#,xamarin.android,layout-inflater,C#,Xamarin.android,Layout Inflater,我想使用LayouInflater以编程方式创建relativeLayout,但它在AddView方法上引发了一个错误,以下是我的代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeAgedSummary" android:layout_width="match_parent" android:layout_h

我想使用LayouInflater以编程方式创建relativeLayout,但它在AddView方法上引发了一个错误,以下是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  android:id="@+id/relativeAgedSummary"     
  android:layout_width="match_parent"
  android:layout_height="match_parent" >
</RelativeLayout>

ViewGroup relativeAgedSummary=FindViewById<ViewGroup>(Resource.Id.relativeAgedSummary);
View view = this.LayoutInflater.Inflate(
                                Resource.Layout.aged_summary_list_item, 
                                relativeAgedSummary, false);    

for (int i = 0; i < agedValues.Count; i++) {
    var row = agedValues.ElementAt(i);
    if(row.Range  == 0 && row.IsTotal == false)
    {
        RelativeLayout rl = view.FindViewById<RelativeLayout>(
                                           Resource.Id.relativeLayoutAgedSummaryItem);
        rl.SetBackgroundResource(Resource.Color.lightBlue); 
        if(contA==0)
        {
           TextView tv = (TextView)view.FindViewById(Resource.Id.txtAgedSummary); 
           tv.SetText(labelsAgedSummary[row.Range], TextView.BufferType.Normal);
           contA++;
        }           
        relativeAgedSummary.AddView(view);
    }

ViewGroup relativeAgedSummary=FindViewById(Resource.Id.relativeAgedSummary);
视图=this.LayoutInflater.flate(
Resource.Layout.age\u摘要\u列表\u项目,
相对性总结,错误);
for(int i=0;i
您所说的“只显示一个”是什么意思。如果您试图将多个实例添加到
relativeAgedSummary
中,则每次您都必须重新膨胀
过期摘要列表项目

for (int i = 0; i < agedValues.Count; i++)
{
    View view = this.LayoutInflater.Inflate(
                    Resource.Layout.aged_summary_list_item, 
                    relativeAgedSummary, false);

    var row = agedValues.ElementAt(i);

    // the logic here...

    relativeAgedSummary.AddView(view);
}
for(int i=0;i

这是因为您多次尝试添加同一对象。它将忽略添加。然后在循环中重复修改同一项,从而导致它看起来好像只添加了“最后”项。

它抛出了什么错误?一个固定的,但现在我想添加更多真实的布局,它只显示一个