I want to create programatically my relativeLayout using LayouInflater but it throws an error on AddView method, heres is my code:
<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);
}
What do you mean "it only appears one". If you are trying to add multiple instances to
relativeAgedSummary
then you will have to re-inflate theaged_summary_list_item
each time:This is because you are trying to add the same object more than once. It will ignore the add. And then in the loop you modify the same item repeatedly, thus resulting in it looking like it added only the "last" item.