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

  • 如果能搜到我這篇文章都應(yīng)該是知道VirtualLayout這個東西的,這是Alibaba開發(fā)的一個LayoutManager,主要是對于RecyclerView的擴(kuò)展,想當(dāng)年我還是很苦逼的處理各式各樣的viewtype,簡直是一段艱辛的歲月,自從有了這個之后就感覺到解放一樣,好了,廢話不多說,這里主要是記述一個第一次使用過程中的錯誤:

      java.lang.IllegalStateException: Cannot change whether this adapter has stable IDs while the adapter has registered observers.
    
  • 解決方法如下:
    一定要使用List容器裝好Adapter再用setAdapters()方法設(shè)置進(jìn)去,否則報錯,至于原因,再看了源碼以后是RecyclerView的原因

      //一定要使用List容器裝好Adapter再用setAdapters()方法設(shè)置進(jìn)去,否則報錯
      List<DelegateAdapter.Adapter> 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);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容