如何创建将听取哈希表更改的函数?

问题描述 投票:0回答:1
private HashMap<Integer, Item> items = new Hashmap<>();

private Flowable<Item> observeItemById(int id) {
  return Flowable.create(emitter -> {
    ???
  },BackpressureStrategy.LATEST);
}

private Flowable<List<Item>> observeItems() {
  return Flowable.create(emitter -> {
    ???
  },BackpressureStrategy.LATEST);
}

//For now I update my hashmap just by putting new items or updating their fields in Item object

每次调用这些函数时,我想创建这些函数的“新实例” /“新侦听器”。当我调用observeItems()时,如果该列表中有任何更改,我想发出列表。但是,当我调用observeItemById(int id)时,当该Item对象发生更改时,应该发出它。

我应该如何创建这些功能?

我应该如何创建我的哈希图,以后对其进行更新以发出这些更改?

java android rx-java2 rx-android
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.