鸿蒙 harmonyOs ListContainer notifyDataChanged()更新无效 原创

qq61358322370d9
发布于 2021-9-15 10:05
浏览
0收藏

ListContainer 的使用过程中遇到的问题

ListContainer 在使用Provider时发现 通过构造方法传入的list 数据 = 赋值 是不能通过 notifyDataChanged() 更新数据的

   //例如  documentBeanTitleList
      
titleProvider = new CommonProvider<DocumentBean>(getContext(), ResourceTable.Layout_item_document_flider, documentBeanTitleList) {
          @Override
          protected void convert(ViewHolder viewHolder, DocumentBean documentBean, int i) {
              Text tvDeptName = viewHolder.getComponent(ResourceTable.Id_tv_deptname);
              DirectionalLayout directionalLayout = viewHolder.getComponent(ResourceTable.Id_ll_item);
              Image image = viewHolder.getComponent(ResourceTable.Id_iv_next);
              tvDeptName.setText(documentBean.getName());
          
              if (i + 1 == documentBeanTitleList.size()) {
                  image.setVisibility(Component.INVISIBLE);
                  try {
                      tvDeptName.setTextColor(new Color(getAbility().getResourceManager().getElement(ResourceTable.Color_black).getColor()));
                  } catch (IOException e) {
                      e.printStackTrace();
                  } catch (NotExistException e) {
                      e.printStackTrace();
                  } catch (WrongTypeException e) {
                      e.printStackTrace();
                  }
              } else {
                  image.setVisibility(Component.VISIBLE);
                  try {
                      tvDeptName.setTextColor(new Color(getAbility().getResourceManager().getElement(ResourceTable.Color_blue).getColor()));
                  } catch (IOException e) {
                      e.printStackTrace();
                  } catch (NotExistException e) {
                      e.printStackTrace();
                  } catch (WrongTypeException e) {
                      e.printStackTrace();
                  }
              }
    
                  }
              });
          }
      };

    listContainer.setItemProvider(titleProvider);

      documentBeanTitleList.add(documentBean);
//  添加 删除 界面更新有效果
                                      
      titleProvider.notifyDataChanged();
 //  = 赋值 的方式 界面更新无效果
      List<DocumentBean> list =new ArryList<>();
       list.add(new DocumentBean());
    documentBeanTitleList = list ; 
       titleProvider.notifyDataChanged();
  //   addAll 的方式有效果
      List<DocumentBean> list =new ArryList<>();
       list.add(new DocumentBean());
      
    documentBeanTitleList.addAll(list) ; 
       titleProvider.notifyDataChanged();
       
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2021-9-15 15:07:07修改
3
收藏
回复
举报
3
3
3条回复
按时间正序
/
按时间倒序
没用的喵叔
没用的喵叔

你这标题误导观众啊!不看内容的人还以为是鸿蒙的bug

回复
2021-9-15 14:54:15
qq61358322370d9
qq61358322370d9 回复了 没用的喵叔
你这标题误导观众啊!不看内容的人还以为是鸿蒙的bug

安卓是可以通过 =  赋值 的  鸿蒙不行    只是为遇到此问题的人提供解决的思路 ,再说标题只能写那么长,我遇到这个问题 想搜索都搜索不到

已于2021-9-15 15:05:50修改
回复
2021-9-15 15:01:32
没用的喵叔
没用的喵叔 回复了 qq61358322370d9
安卓是可以通过 = 赋值 的 鸿蒙不行 只是为遇到此问题的人提供解决的思路 ,再说标题只能写那么长,我遇到这个问题 想搜索都搜索不到

CommonProvider的源码贴一下。我怎么觉得安卓应该也是一样的

回复
2021-9-15 15:08:43


回复
    相关推荐