如何通过更改 recyclerview 中的项目中的值来更新主屏幕中的 textview?

How to update a texview in main screen by changing a value in an item inside a recycleview?

我想开发一个代表商店的屏幕,您可以在其中找到产品列表(由回收视图显示),您可以在其中找到每件商品的价格和 select 您想要的数量。

当用户更新产品数量时,价格也会发生变化。

我在回收视图下方有一个文本视图,显示所有 selected 产品的总价格。

当用户想要更改他对特定产品的需求数量时,更新项目中显示的价格很简单,但是如何同时更新主屏幕中的一个(总计一个)?

使用接口监听回收站视图项目的变化并更新用户select数量的值。 创建接口class

public interface UpdateListener {
    void onQuantityUpdated();

}

在你的适配器中class

 private Context context;
private UpdateListener deleteListener;


public YourRVAdapter(Context context, List<ConsumedMaterialModel> list, 
    UpdateListener updateListener) {
    this.context = context;
    this.list = list;
    this.deleteListener = deleteListener;
}

用户 select 适配器内数量

updateListener.onQuantityUpdated();

现在在您的 Activity

中实现此接口
public class MainActivity extends AppCompatActivity implements UpdateListener


 @Override
public void onQuantityUpdated() {
    //update your textview by calculating amount here
}