Skip to content Skip to sidebar Skip to footer

Recyclerview Periodic Ui Child Updates

I have a recyclerView of items that, (among others), contains a timeStamp of a duration of a game retrieved from a WS. To show the duration of the match, i have to get the current

Solution 1:

As the ViewHolder is going to be recycled by the RecyclerView. You'll need to make sure you're maintaining the stability between the "current game" and the item shown on the list. Despite that i think your solution is fine.

Here's the fix for that:

@OverridepublicvoidonBindViewHolder(MyViewHolder holder, int position) {

        holder.game = mGameList.get(position);
        if (needsUpdate) {
            holder.startRepeatingTask();
        } else {
            holder.stopRepeatingTask();
        }
    }

    classMyViewHolderextendsRecyclerView.ViewHolder {
        privatefinalintmHandlerInterval=6000;
        private Handler mHandler;
        private Runnable mStatusChecker;

        public Game game;

        publicMyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
            mHandler = newHandler();
            mStatusChecker = newRunnable() {
                @Overridepublicvoidrun() {
                    StringgameStatusToPrint= game.getGameStatusToPrint();
                    gameStatus.setText(gameStatusToPrint);
                    mHandler.postDelayed(mStatusChecker, mHandlerInterval);
                }
            };
        }

        publicvoidstartRepeatingTask() {
            mStatusChecker.run();
        }

Post a Comment for "Recyclerview Periodic Ui Child Updates"