Search code examples
androidlistviewxamarinexpandablelistview

AddView() to Expandable ListView


i got a Expandable ListView. I Need to integrate dynamically View(Relative layout with textview) into ListView.
I have an axml file(it's like template for my dynamic views).
I'm doing like this

View _view = LayoutInflater.Inflate(Resource.Layout.DynamicControl,null);  

After that,i'm trying to put into Expandable list(called "_List") :

_List.AddView(_view,0); //where 0 is position(index)

Than i use adapter,to put into ListView data :

_List.SetAdapter(new _Adapter(this, List<MyClass>, _List));  

IDE give me exception :

java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView

I read that,AddView() doesnt integrate in listView views and i need to use(always) adapter. Is that true?(Maybe exist workaround or i can override my constructor(Of Custom _Adapter) and give another parametrs,like Context and Views?).
By the way,why AddFooterView / AddHeaderView work properly ?

PS Sorry for my eng. Thanks!

UPD :

https://i.sstatic.net/5LhLA.png

"My New View" - // Row for Expandable ListView,which is RelativeLayout(into this Layout i got TextView).  

How can i do something like this?


Solution

  • So the workaround was(for me),to generate post condition and put different layouts :

    var inflater = _context.GetSystemService(Context.LayoutInflaterService) as  LayoutInflater;
    
      if(!SpecificLayout)
        {
          view = inflater.Inflate(Resource.Layout.SpecificLayout, null);
        }
      else
        {
          view = inflater.Inflate(Resource.Layout.AnotherLayout, null);
        }