Home  >  Q&A  >  body text

java - weeex[android]list的实现itemview没有进行重用

list的实现使用的是RecyclerView,但getItemViewType返回的是dom的ref,ref在一个dom树里应该是唯一的;

public int getItemViewType(int position) {
    return generateViewType(getChild(position));
  }
private int generateViewType(WXComponent component) {
    long id;
    try {
      id = Integer.parseInt(component.getDomObject().getRef());
      String type = component.getDomObject().getAttrs().getScope();

      if (!TextUtils.isEmpty(type)) {
        if (mRefToViewType == null) {
          mRefToViewType = new ArrayMap<>();
        }
        if (!mRefToViewType.containsKey(type)) {
          mRefToViewType.put(type, id);
        }
        id = mRefToViewType.get(type);

      }
    } catch (RuntimeException e) {
      WXLogUtils.eTag(TAG, e);
      id = RecyclerView.NO_ID;
      WXLogUtils.e(TAG, "getItemViewType: NO ID, this will crash the whole render system of WXListRecyclerView");
    }
    return (int) id;
  }
大家讲道理大家讲道理2743 days ago508

reply all(2)I'll reply

  • 阿神

    阿神2017-04-18 10:55:21

    Reuse requires views of the same type.
    According to the description, the type of each item is unique, that is, they are not the same thing. The code cannot tell whether it can be reused.
    There should be confusion here. The unique identifier (id) required elsewhere is mixed with the type required by RecyclerView. If you want the Views of two Items to be shared, the types of the two Views should be the same (their IDs may be different)

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:55:21

    +1 The itemtype above is different and cannot be reused

    reply
    0
  • Cancelreply