update some element of the recyclerView card

Viewed 29

I was using the binance API with retrofit so I was receiving an array with the data, mapping to my custom UI object and uploading  all in the recyclerView over 2/3 seconds with liveData

LiveData in the fragment

viewModel.cryptoListLD.observe(viewLifecycleOwner){ cryptoAdapter.setData(it) }

RecyclerViewAdapter

fun setData(cryptos: List<CryptoUI>){
    cryptoList = cryptos
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
    with(holder){
        setImg(cryptoList[position].imgUrl)
        setSymbol(cryptoList[position].Symbol)
        setName(cryptoList[position].name)
        setPrice(cryptoList[position].price)
        setPriceVariation(cryptoList[position].priceVariation)
    }
}

Now, I want to know if it's possible to update only some part of the recyclerView card, and not all the item because I want to implement some call to the binance web socket that returns a lot of data per second and I don't want to overload the performance.

In this case, I want to update only the price and the variation, but maintain the same image and name.

card item

1 Answers

Try to access data from the firebase and use DocumentSnapshot as shown below. Repeat the same for the variation.

        db.collection(yourcollectionName)
            .whereEqualTo("price", cryptoList.getPrice() )
            .get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    final Double[] Price = {0.0};
                    List<DocumentSnapshot> documentSnapshotList = queryDocumentSnapshots.getDocuments();

                    for(DocumentSnapshot ds: documentSnapshotList) {
                        Price[0] = (Double) ds.get("yourattributename") + Price[0];

                    }

                    holder.price.setText(String.valueOf("$"+Price[0]));

                }
            });
Related