AddView() 到可扩展的 ListView

AddView() to Expandable ListView

我有一个可扩展的 ListView。我需要将 View(与 textview 的相对布局)动态集成到 ListView 中。
我有一个 axml 文件(它就像我的动态视图的模板)。
我这样做

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

在那之后,我试图放入可扩展列表(称为“_List”):

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

比起我使用适配器,将数据放入 ListView 中:

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

IDE 给我例外:

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

我读到,AddView() 没有集成到 listView 视图中,我需要(总是)使用适配器。这是真的吗?(也许存在解决方法,或者我可以覆盖我的构造函数(自定义 _Adapter)并提供另一个参数,如上下文和视图?)。
顺便问一下,为什么 AddFooterView / AddHeaderView 可以正常工作?

PS 对不起我的工程师。谢谢!

更新:

http://i.stack.imgur.com/5LhLA.png

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

我怎样才能做这样的事情?

addView() not supported in AdapterView. Blockquote

这意味着 AdapterView -> ListView, ExpandableListView, ViewPager ...等

我不知道该做什么。 给我看样机,或 UI 的任何图片。那我可以帮你吗。

是的,我们只能在 adapter.For 添加自定义视图的帮助下将视图添加到列表视图,我们需要通过扩展其中一个适配器 class 来定义我们自己的适配器,例如 BaseAdapterCursorAdapter

例如:我们有

public class ContactListAdapter extends BaseAdapter{
    private List<String> name;
    private LayoutInflater layoutInflater;

    public ContactListAdapter(Activity activity) {
        layoutInflater = activity.getLayoutInflater();
        name = new ArrayList<String>();
    }

    public void addMessage(String message) {
        name.add(message);
        notifyDataSetChanged();
    }
    public void removeMessage(String message) {
        name.remove(message);
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return name.size();
    }

    @Override
    public Object getItem(int i) {
        return name.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int i) {
         return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        int direction = getItemViewType(i);


                 if (convertView == null) {

            //LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.contact_list, viewGroup, false);
        }

        String message = name.get(i);



        final TextView txtMessage = (TextView) convertView.findViewById(R.id.contactName);
        txtMessage.setText(message.toString());

        ImageView imageView=(ImageView)convertView.findViewById(R.id.contactImage);

        return convertView;
    }
}

此适配器添加了一个包含一张图片和一个 TextView 的联系人列表视图。 添加页眉和页脚视图只是定义固定的页眉和页脚部分,与具有所有相同类型视图的列表视图无关页眉和页脚可以不同。

所以解决方法是(对我而言)生成 post 条件并放置不同的布局:

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);
    }