Search code examples
androidandroid-recyclerviewadapter

How to update data in Activity from recycler adapter instantly?


Hello there! I am developing a shopping application where user can set items quantity and the recycler will show instant pricing according to the quantity. but the problem I am facing is I cant update the total price section in my Activity.

enter image description here


Solution

  • Write a Callback like this in your adapter

    interface OnItemUpdateListener{
    void onUpdateTotal(int total)
    }
    

    Then register that callback in your adapter from your activity, and on click increment or decrement call that callback

    onItemUpdateListener.onUpdateTotal(total)
    

    Then in Your activity you can override onUpdateTotal(int total) method, Set value of total_textview here.