There is a CartActivity activity in which RecyclerView is located. There is also a class RecyclerViewAdapter. For ViewHolder, ClickListener is registered, where the user is shown an AlertDialog with a suggestion to remove the selected item from the list.
CarActivity.java
... while (cursor.moveToNext()) { currentItem = new Item(); currentItem.setId( cursor.getInt(idColumnIndex)); currentItem.setName(cursor.getString(nameColumnIndex)); currentItem.setPrice(Double.parseDouble(cursor.getString(priceColumnIndex))); currentItem.setAmount(Integer.parseInt(cursor.getString(amountColumnIndex))); currentItem.setImage(cursor.getString(imageColumnIndex)); sumOrder += currentItem.getPrice()*currentItem.getAmount(); items.add(currentItem); } mAdapter = new RecyclerViewAdapter(items, R.layout.row, this); mRecyclerView.setAdapter(mAdapter); progressBar.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); txtSumOrderView.setText(getString(R.string.txt_sum_order, sumOrder)); ... RecyclerViewAdapter.java
... viewHolder.itemView.setOnClickListener(view -> { alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", (dialog, which) -> { items.remove(currentItem); notifyDataSetChanged(); } }); alertDialog.show(); } ... How do you tell the activity that the items list array with RecyclerView has changed to recalculate the total amount of the remaining positions and update the text in the TextView element of the activity?