VirtualLayout:Cannot change whether this adapter has stable IDs while the adapter has registered observers.

  • 如果能搜到我这篇文章都应该是知道VirtualLayout这个东西的,这是Alibaba开发的一个LayoutManager,主要是对于RecyclerView的扩展,想当年我还是很苦逼的处理各式各样的viewtype,简直是一段艰辛的岁月,自从有了这个之后就感觉到解放一样,好了,废话不多说,这里主要是记述一个第一次使用过程中的错误:

      java.lang.IllegalStateException: Cannot change whether this adapter has stable IDs while the adapter has registered observers.
    
  • 解决方法如下:
    一定要使用List容器装好Adapter再用setAdapters()方法设置进去,否则报错,至于原因,再看了源码以后是RecyclerView的原因

      //一定要使用List容器装好Adapter再用setAdapters()方法设置进去,否则报错
      List adapters = new ArrayList<>();
      CommonAdapter adapter1 = new CommonAdapter(this, new LinearLayoutHelper(), R.layout.item, list) {
          @Override
          public void convert(ViewHolder holder, Object o, int position) {
              holder.setText(R.id.text01, position + "");
          }
      };
      adapters.add(adapter1);
      CommonAdapter adapter2 = new CommonAdapter(this, new GridLayoutHelper(3), R.layout.item, list) {
          @Override
          public void convert(ViewHolder holder, Object o, int position) {
              holder.setText(R.id.text01, position + "");
          }
      };
      adapters.add(adapter2);
      adapter.setAdapters(adapters);

你可能感兴趣的:(VirtualLayout:Cannot change whether this adapter has stable IDs while the adapter has registered observers.)