jaychang0917 / SimpleRecyclerView

A RecyclerView extension for building list more easily.
Apache License 2.0
935 stars 104 forks source link

SimpleCell Bug #29

Closed Larnoo closed 7 years ago

Larnoo commented 7 years ago
  protected abstract long getItemId();

When DownloadCell getItemId() return 0. the recycler cell method onBindViewHolder will never be called.

The log of my debug are as follow. Why onBindViewHolder called, must call getItemId? I must provide a valid id for cell?

E: getItemId: a(cell data)
E: getItemId: a(cell data)
E: onBindViewHolder: position=1; aa(cell data)
E: getItemId: b(cell data)
E: getItemId: b(cell data)
E: onBindViewHolder: position=2; b(cell data)
E: getItemId: c(cell data)
E: getItemId: c(cell data)
E: onBindViewHolder: position=3; c(cell data)
    private class DownloadCell extends SimpleCell<DownloadBean, DownloadViewHolder> {

        private DownloadCell(DownloadBean item) {
            super(item);
        }

        @Override
        protected int getLayoutRes() {
            return R.layout.adapter_offline_download_item;
        }

        @NonNull
        @Override
        protected DownloadViewHolder onCreateViewHolder(ViewGroup viewGroup, View view) {
            return new DownloadViewHolder(view);
        }

        @Override
        protected void onBindViewHolder(DownloadViewHolder holder, int i, Context context, Object o) {
            DownloadBean item = getItem();
            OfflineManager.DownloadTileInfo info = item.downloadTileInfo;
            holder.textTileName.setText(info.getTileName());
        }

        @Override
        protected long getItemId() {
           // don't have a valid id.
            return 0;
        }
    }
jaychang0917 commented 7 years ago

@Larnoo pls provide a demo project that can reproduce this issue.

jaychang0917 commented 7 years ago

The issue should be fixed.

Larnoo commented 7 years ago

The SimpleCell method getItemId if can't provide a valid id, must return View.NO_ID, not 0. the bug fix. @jaychang0917

@Override
        protected long getItemId() {
           // don't have a valid id.
            return 0;
        }