O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling multiple records on the UI

After an introduction of the regular updates of the stock quotes, it can soon be noticed that it generates lots of duplicate entries in the RecyclerView list.

The problem is that quite often the stock doesn't change right away, so we will see lots of duplicate or rather irrelevant entries.

This issue can be fixed by updating the .add() method of StockDataAdapter to as illustrated:

public void add(StockUpdate newStockUpdate) {    for (StockUpdate stockUpdate : data) {        if (stockUpdate.getStockSymbol().equals           (newStockUpdate.getStockSymbol())) {            if (stockUpdate.getPrice().equals               (newStockUpdate.getPrice())) {               return;            }            break;        }    }    this.data.add(0, newStockUpdate);    notifyItemInserted(0);}

What this new code basically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required